enpit / fleux

Towards Sane State Management in React

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default Context

objectliteral opened this issue · comments

Currently, the use of withState requires a store to be connected to the component hierarchy with connect. When a stateful component is rendered and no store was set in the context, an error is thrown.

At the least, the error message in this situation could be improved, I think. Currently, this gets written to the console:

The above error occurred in the <_class> component:
    in _class
    in Unknown (created by Context.Consumer)
    in Unknown (created by ComponentWithState)
    in ComponentWithState (at main.js:24)
    in div (at main.js:23)
    in App (at main.js:69)

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries. react-dom.development.js:17117:12
    React 13
    unstable_runWithPriority scheduler.development.js:255
    React 14
    parcelRequire<["main.js"]</< main.js:69
The above error occurred in the <_class> component:
    in _class
    in Unknown (created by Context.Consumer)
    in Unknown (created by ComponentWithState)
    in ComponentWithState (at main.js:25)
    in div (at main.js:23)
    in App (at main.js:69)

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries. react-dom.development.js:17117:12
TypeError: store is undefined
hoc.js:16:82
TypeError: store is undefined
hoc.js:16:82

Suggestion

This could be improved, by fleux catching this case and printing are more helpful error message.

A second improvement in that regard would be, to make a default store available to all stateful components. This would also simplify the library usage even further, since a call to connect would no longer be necessary (though still possible and potentially useful).

This was added in 0fce9b8