我想在單擊按鈕時將狀態設定為他以前的值.......將 redux-state 更改為以前的 redux-state
減速器檔案
export var key = (state = 0, action) => {
if (action.type === 'changeKey') {
return action.playload
}
else {
return state
}
}
動作檔案
export var keyAction = (name) => {
return {
type: 'changeKey',
playload: name,
}
}
3 檔
<Text onPress={()=>{
//what i need to write here ???
}}> Set redux-state to previous value of redux-state</Text>
uj5u.com熱心網友回復:
您可以使用redux-undo(https://github.com/omnidan/redux-undo)或按照本檔案https://redux.js.org/usage/implementing-undo-history實作您自己的自定義邏輯
uj5u.com熱心網友回復:
您應該發送您的 redux 操作
import { useDispatch } from 'react-redux'
const FC = () => {
const dispatch = useDispatch()
return (
<Text onPress={() => dispatch(keyAction("stackoverflow"))}>
Set redux-state to previous value of redux-state
</Text>
)
}
你還寫了playload而不是payload
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/345872.html
上一篇:如何顯示兩個反應組件
下一篇:呈現此功能組件的更好方法是什么?
