This function will be called by Component and the current version of the state will be passed as an argument. This way is called a “functional update.”
This might be useful whenever you need multiple asynchronous functions (doStuff) to share a state.
More flexible middleware:
setState cannot receive an callback as a 2nd param, cos schema is the 2nd param...
So cant do this:
// call set state, and pass in an array of functions to run
// immediately after state is updated, and before render()
// is called
Foo.setState({ ... someData }, [ fn1, fn2 ]);
But could do this instead:
If middleware is an object, user can choose when to run the middleware:
on initial render() into page
before setState()
after setState(), but before render()
after render() (middleware currently does this one only)
Instead of only passing objects to
setState
, make it possible to pass functions too:This function will be called by Component and the current version of the state will be passed as an argument. This way is called a “functional update.”
This might be useful whenever you need multiple asynchronous functions (
doStuff
) to share a state.More flexible middleware:
setState
cannot receive an callback as a 2nd param, cos schema is the 2nd param...So cant do this:
But could do this instead:
If middleware is an object, user can choose when to run the middleware:
render()
into pagesetState()
setState()
, but beforerender()
render()
(middleware currently does this one only)...or something similar..