atlassian / react-sweet-state

Shared state management solution for React
https://atlassian.github.io/react-sweet-state/
MIT License
871 stars 55 forks source link

Fix selector returning a function #107

Closed albertogasparin closed 4 years ago

albertogasparin commented 4 years ago

Returning a function is quite bad as will invalidate memoisation on every state update, yet currently it breaks as useState will execute that function on hook mount. By switching to lazy useState we can store the selector output into the state even if that is itself a function.