Я хочу установить переменную в магазине. Вот мой магазин
class storeCategory{
@observable categories =[];
@action getCategories = () =>{
fetch('http://localhost:3000/categories')
.then((resp) => resp.json())
.then(function(resp2){
this.categories=resp2;
});
}
}
вот мой компонент
@inject('sCategory')
@observer
class Category extends React.Component{
componentDidMount=()=>{
this.props.sCategory.getCategories();
}
render(){
const {sCategory} = this.props;
return (
<ListGroup>
{this.props.sCategory.categories.map((cat, index) => {
return (
<ListGroupItem key={cat.id}>{cat.categoryName}</ListGroupItem>
)
})}
</ListGroup>
);
}
}
Я добавляю в sКатегорию к провайдеру в index.js
Я получаюэта ошибка в this.categories = resp2 в методе выборки;
Невозможно установить свойство 'category' из неопределенного