很有趣,我正在使用 redux-orm,但发现我很难使用 react-redux(尽管它被称为 redux-orm)。
我得到了TypeError: Cannot read property 'Article' of undefined by using your method。
让我稍微绕开这个问题。
有没有比 redux-orm 更流行的 ORM 库,它在互联网上只有几个例子。
文章.js
```
class Article extends Model {
static reducer(action, Article, session) {
switch (action.type) {
case 'load_all':
action.payload.forEach(articleData=>{
Article.create(articleData);
})
return session;
break;
}
return undefined;
}
}
Article.modelName = 'Article'
Article.fields = {
id: attr(), // non-relational field for any value; optional but highly recommended
name: attr(),
};
export default Article;
```
orm.js
const orm = new ORM ({
stateSelector: state => state.orm,
});
orm.register(Article);
文章列表.js
const articlesSelector = createSelector(orm.Article);
const ormArticles = useSelector(state => articlesSelector(state, null));