【问题标题】:Tying to add a variable to a state using hooks使用钩子将变量添加到状态
【发布时间】:2019-08-14 09:24:38
【问题描述】:

我无法将 imageData 添加到我的状态变量

setValues(prevState => ({ ...prevState, imageData: source.uri }));

const [autoData, setValues] = useState(state);

【问题讨论】:

    标签: react-native react-hooks


    【解决方案1】:

    创建状态变量并将其添加为对象。

    
      const updateField = e => {
        setValues({
          ...autoData,
          [imageData]: e.value
        });
      };
    
      const [autoData, setValues] = useState({});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-27
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      相关资源
      最近更新 更多