【问题标题】:React Redux nested Component Mui TextField doesn't update with state changeReact Redux 嵌套组件 Mui TextField 不会随着状态变化而更新
【发布时间】:2023-01-10 10:12:11
【问题描述】:

我正在努力让 react / redux 状态组件刷新

我要显示的内容按预期得到处理。 我通过 redux useSelector hook 在组件中获取它。

const content = useSelector(my.select.content, helper.customEqual);

该组件显示一个标题,一个根据内容动态构建的框。

  • 标题和 div 块按预期刷新

  • TextField(是 MaterialTextField,见下文):

    • defaultValue 不刷新,如果键不存在,则该字段添加正确的值/删除
    • 标签刷新
<Typography variant="headline" component="h3">
  {title}: {content.label  } 
</Typography>
<Box
  component="form"
>
  {
    Object.keys(content)
    .map(key => {
      return (
        <Typography color="textSecondary">
          <div>{key}: {content[key]  /* this refreshes */} </div>
          <TextField
    
            label={content[key]}  /* should be:  label={key} */  
            defaultValue={content[key] }
          />
        </Typography>
      )
    })
  }
</Box>

为了完整起见,(Mui) TextField 是一个 Atom,我在这里没有看到与 react/redux 相关的问题,但是如果 id 存在相同的值,它可能不会重新呈现?

【问题讨论】:

    标签: reactjs react-redux material-ui


    【解决方案1】:

    在输入问题时进行挖掘,发现它确实是TextField 中与 Mui 相关的错误配置。

    defaultValue    any     The default value. Use when the component is not controlled.
    value           any     The value of the input element, required for a controlled component.
    

    切换到value 完成了工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-17
      • 2016-10-02
      • 2017-05-19
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多