公式ドキュメントから 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が初めてで、助けていただければ幸いです。ありがとう。