I want to implement many-to-many relationship in Redux. My reducer looks like this:
const INITIAL_ARTICLES = {
articles: [],
tags: []
}
const articles = (state = INITIAL_ARTICLES, action) => {
switch(action.type){
case 'ADD_ARTICLE':
return {
...state,
articles: [...state.articles, action.item]
}
default:
return state
}
}
I created many-to-many relationshiop in Laravel. All articles is fetch from my db but I want to implement many-to-many relationship. The best for me would be if this state would look like this:
const INITIAL_ARTICLES = {
articles: [
{
id: 1,
title: "My firs article",
tags: [
{
id: 1,
name: "tag"
},
{
id: 2,
name: "cats"
}
]
}
]
}
Is it possible? How can I implement this relatioship with those or other way? I think primarilly about reducer.
question from:
https://stackoverflow.com/questions/65857099/implement-many-to-many-relationship-in-redux 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…