const QuotePage = Snapshot({
quote: props => fetch(`/api/quotes/${props.id}`).then(response => response.json())
}, {
renderWithNulls: true
})(
({ quote }) => quote
?
<div>
<div className="Quotes">
<Quote quote={quote}/>
</div>
</div>
:
<Spinner/>
)
export default Snapshot({
quotes: () => fetch('/api/quotes').then(resp => resp.json())
}).rendering(Home)
.rendering
if you want it to render with nulls to begin with or .thenRender
if you want it to wait
snapshot
with a Promise.all: https://github.com/geelen/react-snapshot/blob/async/src/index.js#L65-L73
componentWillMount() {
snapshot(() =>
Promise.all(prop_names.map(prop_name => prop_defs[prop_name](this.props)))
).then(responses => {
const new_state = {}
prop_names.forEach((prop_name, i) => new_state[prop_name] = responses[i])
this.setState({ async_props: new_state, loaded_all: true })
})
}