fable-compiler / fable-react

Fable bindings and helpers for React and React Native
MIT License
273 stars 67 forks source link

Can't update shared state passed with useContext? #229

Closed playfulThinking closed 2 years ago

playfulThinking commented 2 years ago

I'm using useContext to share state among components. I can't for the life of me see how to update the state, as useContext only returns the state, but not an updater function, as React does. I know that useState returns objects with current and update functions, but useContext does not.

What am I missing?

Thanks much!

playfulThinking commented 2 years ago

Well this is embarrassing. I misread the Reactjs documents and thought useContext was shaped like useState, with an updater function as part of the return. It is not - you have to include an updater function in the state yourself.

Whoopsie!

alfonsogarciacaro commented 2 years ago

Sorry for the late reply and thanks for confirming the solution @fremontmj. Yes, Fable.React are meant to be a more or less direct binding to React API so (unless there's a bug in the bindings) it should behave in the same way as React API... with all the quirks this entails ;)

playfulThinking commented 2 years ago

@alfonsogarciacaro Late reply? LOL I just find it amazing that you have time for your great work, which is amazing, AND writing to random bozo newbie developers who can't read documentation (especially embarrassing b/c the React Hooks documentation is just amazingly good!)

Best regards and huge thanks,

Mike