(Redux工具包)如何访问CreatesLice之外的状态
在我的项目中,我想在slice.js
中放置尽可能多的逻辑和功能。有时我想创建或导出createSlice
之外的功能
const checkValid = () => {
```need to access the current state to check for validation```
}
export const boardSlice = createSlice({
name: 'board',
initialState,
reducers: {
check: (state, actions) => {
checkValid(actions.payload);
}
}
});
:解决方案是在降低器
中直接将状态与action.payload
一起传递。但是有更好或官方的方法吗?另外,将与逻辑放在切片中一样好吗?非常感谢。
In my project, I want to put as much as logic and function inside the the slice.js
. Sometime I want to create or export the function outside of the createSlice
like this:
const checkValid = () => {
```need to access the current state to check for validation```
}
export const boardSlice = createSlice({
name: 'board',
initialState,
reducers: {
check: (state, actions) => {
checkValid(actions.payload);
}
}
});
The checkValid
need to access the state in the store
, my current solution is directly passing the state as props along with the actions.payload
in the reducer
. But is there a better or official way of doing this? Also, is it good to put as much as logic inside the slice? Much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我与您分享使用的方法,希望它有助于
更多地使用额外的还原器
结帐此 https://www.youtube.com/watch?v
Let me share with you what am using, hope it helps
for more clalification on the use of extra reducers
checkout this https://www.youtube.com/watch?v=mvfsC66xqj0