【发布时间】:2021-01-22 08:42:56
【问题描述】:
伙计们,我正在尝试使用 react-native expo 从列表中删除一个元素
但它一直说delete_post 不起作用
const ReduceBlogPost = (state, action) => {
switch (action.type) {
case 'delete_post':
return state.filter((blogs) => blogs.id !== action.playload);
case 'add_Blog_Post':
return [...state, { id: Math.floor(Math.random() * 9999), title: `blog number one #${state.length + 1}` }];
default:
return state;
}
};
export const BlogProvider = ({ children }) => {
const [blogs, dispatch] = useReducer(ReduceBlogPost, []);
// updateBlog
const updateBlog = () => {
dispatch({ type: 'add_Blog_Post' });
};
//delete blog post
const delete_blog = (dispatch) => {
return (id) => {
dispatch({ type: 'delete_post', playload: id });
};
};
return <BlogContext.Provider value={{ data: blogs, updateBlog }}>{children}</BlogContext.Provider>;
};
【问题讨论】:
标签: reactjs react-native expo react-native-elements