Skip to content

Instantly share code, notes, and snippets.

@oshell
Created March 19, 2020 17:28
Show Gist options
  • Save oshell/e03006bd0c62aa87d0aa4901847708f8 to your computer and use it in GitHub Desktop.
Save oshell/e03006bd0c62aa87d0aa4901847708f8 to your computer and use it in GitHub Desktop.
Reactn Class Example
import React from 'reactn'; // <-- reactn
import Card from '../card/card';
export default class Cards extends React.PureComponent {
componentDidMount() {
// Hydrate the global state with the response from /api/cards.
this.setGlobal(
fetch('/api/cards')
.then(response => response.json())
.then(cards => ({ cards }))
.catch(err => ({ error: err })),
);
}
render() {
return (
<div>
{this.global.cards.map(card => (
<Card key={card.id} {...card} />
))}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment