我正在从官方文档中学习 redux-toolkit 并遇到了这一行 -Also, the action creator overrides toString() so that the action type becomes its string representation.
这是什么意思?
这是文档中的代码:
const INCREMENT = 'counter/increment'
function increment(amount) {
return {
type: INCREMENT,
payload: amount
}
}
const action = increment(3)
// { type: 'counter/increment', payload: 3 }
const increment = createAction('counter/increment')
let action = increment()
// { type: 'counter/increment' }
action = increment(3)
// returns { type: 'counter/increment', payload: 3 }
console.log(increment.toString())
// 'counter/increment'
console.log(`The action type is: ${increment}`)
// 'The action type is: counter/increment'
所以,例如,当我写类似的东西时
const increment = createAction("INCREMENT")
console.log(increment.toString())
它正在记录INCREMENT
。那么这是 toString() 的覆盖吗?我真的很困惑。
我是 redux-toolkit 的新手,任何帮助将不胜感激。谢谢。