Avarios / use-lilius

📅 A headless calendar hook for React.
https://use-lilius.vercel.app/
MIT License
275 stars 20 forks source link

Potential React Context implementation. #490

Closed jblevins1991 closed 2 years ago

jblevins1991 commented 2 years ago

Is your feature request related to a problem? Please describe.

My team is building a custom date picker and we didn't want to build the calendar into the component because there are many edge cases that a design system team is not responsible for (one off requests that would waste our time and slow us down). To solve the problem of these one offs on our date picker, we made the calendar component a render prop to allow other teams to replace the default calendar we built. The issue is, without using the context api we are using an anti-pattern called prop drilling because the values the calendar needs is in the DatePicker component, and without context, we cannot pull them into the calendar using a hook.

Describe the solution you'd like

I think all React.setState and other state values could be moved to a context provider so that we may pull values from any component wrapped within it. This would remove the prop drilling anti pattern.

Describe alternatives you've considered

Not many alternatives to consider.

its-danny commented 2 years ago

I'm not against adding an optional Context, though I would like to not break how it currently works for use-cases where you don't need to share state.

That said, is there anything preventing you from wrapping it yourself? A better solution would maybe be to change whatever is preventing that instead of use-lilius handling it itself.

An example of how you could do it without any changes to use-lilius: https://codesandbox.io/s/use-lilius-in-context-5y85ly