I have the below fetch request in my Mobx store:
getAllLegoParts = action("get all lego", () => {
this.legoParts = fromPromise(
fetch("http://localhost:8000/LegoPieces", {
method: "GET",
cache: "no-store"
}).then(response => response.json())
);
});
}
I am using this in the below ReactJS class:
class ViewLegos extends Component {
constructor(props) {
super(props);
this.props.store.getAllLegoParts();
}
render() {
console.log(this.props.store.legoParts.value);
return (
<div>
<table>
<thead>
<tr>
<th>Piece</th>
<th>Type</th>
</tr>
</thead>
<tbody>
{this.props.store.legoParts.map(legoPart => (
<tr key={legoPart.id}>
<td>{legoPart.piece}</td>
<td>{legoPart.piece}</td>
<td>{legoPart.type}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
}
export default inject("store")(observer(ViewLegos));
However I have two issues:
Console.log prints twice - in one case in prints undefined, in the second it prints an array of objects(which is what I want).
I get an error saying:
TypeError: this.props.store.legoParts.map is not a function
Grateful for your help!