_A generic, optimistic update helper._
npm install react-optimistic_A generic, optimistic update helper._
``jsx
import Optimistic from 'react-optimistic'
// ...
{({ state, reqState, updater }) =>
className="optimistic-btn"
onClick={updater(successfulAction)} // successfulAction returns a Promise
>
{state}
Request state: {reqState}
}
`
A naive, optimistic button.
- Optimistic : ReactComponent
The Optimistic component takes a render prop with the following signature:
`typescript`
interface Args {
state: string
reqState: string
updater: function
reset: function
}
let renderProp: (args: Args) => ReactElement
- props
- children: renderProp
- initialState : string
Example
`jsx``
const Foo = ({ onClick }) =>
{({ state, updater }) => }