In my App.js file I have the following code snippet:
import stores from 'client/stores';
...
...
render() {
return (
<Provider {...stores}>
<SafeAreaView>
<AppContainer />
</SafeAreaView>
</Provider>
);
}
To fetch data from the backend and pass it to AppContainer
asynchronously using a promise, here is an example:
// client/stores/index.js
boardsService.retrieveBoards().then(boards => {
// Code to store retrieved boards
})
You can then inject the boards into AppContainer
:
export default
@inject('boards')
@observer
class AppContainer extends React.Component {
constructor(props) {
super(props);
console.log(props.boards);
}
render() {
...
}
}
I attempted to do this in stores/index.js as well:
async function connect() {
const connection = await boardsService.retrieveBoards();
if (connection) {
return connection;
}
return null;
}
connect().then(boards => {
exports.boards = boards;
});
However, I encountered the following error message: