react-hooker
this is a simple HOC for organizing network behaviour
;; static hooks = Promise items: id: 0 displayName: 'cat' price: 35 id: 1 displayName: 'phone' price: 35 { // use this when there is network connectivity thisprops; // use this one when in offline mode! // this.props.loadFakeItems(); // or // this.props.loadSyncItems(); } { const items= } = thisprops; return <ul> items </ul> ; } App;
for observables / sockets / triggering updates from a / calling a hook multiple times
{ thisnext = next thisdone = done thiserr = err; thiscount = 0; } { ; } { ifthisinterval ; if !args0 this; else if args0 < 0 this; else thisinterval = ; } ; // from ./network, into the static hooks eventually
this example will make an interval of whatever length you tell it when calling the hook, to update props.count
thisprops;
calling it again will clear the old interval so you can change the tick length
thisprops;
without restarting the count
cleanup will be called when the component dismounts (componentWillUnmount)
or when calling the handler with 0
thisprops;
by triggering the done callback
...
errors end up on this.props[hookName+'HookErr']
thisprops; //... { console; // 'negative tick length not allowed' return <JSX/>;}
you can also return a promise from handleRequest that will be the result of calling the hook each time, resolved after the setState is done (and so your props will be updated)