小编Buk*_*Lau的帖子

从材料 ui 处理自动完成组件的更改

我想将Autocomplete组件用于输入标签。我正在尝试获取标签并将它们保存在状态中,以便稍后将它们保存在数据库中。我在反应中使用函数而不是类。我确实尝试过onChange,但没有得到任何结果。

<div style={{ width: 500 }}>
  <Autocomplete
    multiple
    options={autoComplete}
    filterSelectedOptions
    getOptionLabel={(option) => option.tags}
    renderInput={(params) => (
      <TextField
        className={classes.input}
        {...params}
        variant="outlined"
        placeholder="Favorites"
        margin="normal"
        fullWidth
      />
    )}
  />
</div>;
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui

35
推荐指数
5
解决办法
8万
查看次数

React Hook useEffect 缺少依赖项:'dispatch'

这是我第一次使用 react js,我试图在离开此视图时删除警报,因为我不想在另一个视图上显示它,但如果没有错误,我想保持成功警报以显示当我要重定向到另一个视图时

但我在谷歌浏览器上穿上了这件衣服 Line 97:6: React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhaustive-deps

如果我确实包括调度,我会得到无限循环

const [state, dispatch] = useUserStore();
useEffect(() => {
    let token = params.params.token;
    checktoken(token, dispatch);
  }, [params.params.token]);

  useEffect(() => {
    return () => {
      if (state.alert.msg === "Error") {
        dispatch({
          type: REMOVE_ALERT
        });
      }
    };
  }, [state.alert.msg]);

//response from the api
if (!token_valide || token_valide_message === "done") {
      return <Redirect to="/login" />;
    }
Run Code Online (Sandbox Code Playgroud)

这是 useUserStore

  const globalReducers …
Run Code Online (Sandbox Code Playgroud)

reactjs react-hooks

28
推荐指数
1
解决办法
3万
查看次数

componentWillReceiveProps 已重命名

我正在使用使用 ReactSwipableView 包的 Material ui SwipeableViews,我在控制台上收到此错误

react-dom.development.js:12466 警告:componentWillReceiveProps 已重命名,不推荐使用。详情请参阅。

  • 将数据获取代码或副作用移动到 componentDidUpdate。
  • 如果您在道具更改时更新状态,请重构您的代码以使用记忆技术或将其移动到静态 getDerivedStateFromProps。了解更多信息:
  • 将 componentWillReceiveProps 重命名为 UNSAFE_componentWillReceiveProps 以在非严格模式下抑制此警告。在 React 17.x 中,只有 UNSAFE_ 名称有效。要将所有已弃用的生命周期重命名为其新名称,您可以npx react-codemod rename-unsafe-lifecycles在项目源文件夹中运行。

请更新以下组件:ReactSwipableView

有什么办法可以摆脱这个错误我确实尝试过 UNSAFE_componentWillReceiveProps 但没有任何改变

reactjs

23
推荐指数
2
解决办法
5万
查看次数

标签 统计

reactjs ×3

material-ui ×1

react-hooks ×1