Created
March 19, 2020 17:28
-
-
Save oshell/e03006bd0c62aa87d0aa4901847708f8 to your computer and use it in GitHub Desktop.
Reactn Class Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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