小编L. *_*rto的帖子

为什么React中的道具是只读的?

React文档说: React is pretty flexible but it has a single strict rule: all React components must act like pure functions with respect to their props.

这是为什么?

我猜想,如果您直接更改props的值,则组件不会重新渲染,这就是我们必须使用的原因setState。但我仍然不了解其背后的原因。为什么组件在其道具方面必须像纯函数一样?

pure-function reactjs

5
推荐指数
1
解决办法
3823
查看次数

Redux 工具包:未捕获类型错误:无法读取未定义的属性(读取“类型”)

当我在extraReducers切片内部添加特定操作时,出现以下错误:

Uncaught TypeError: Cannot read properties of undefined (reading 'type')

例子:

import { createSlice } from '@reduxjs/toolkit'

export const mySlice = createSlice({
  name: 'name',
  initialState,
  extraReducers: (builder) => {
    // If I console.log action2 here, it turns out to be undefined
    builder.addCase(action1, () => ...) 
    builder.addCase(action2, () => ...) // when I add this specific action I get the error.
  },
  reducers: {
    ...
  },
})
Run Code Online (Sandbox Code Playgroud)

action2的定义类似于action1另一个文件中的 :

import { createAction } from '@reduxjs/toolkit' …
Run Code Online (Sandbox Code Playgroud)

javascript redux redux-reducers redux-toolkit

5
推荐指数
1
解决办法
8343
查看次数