Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React不在redux存储更改时重新呈现映射函数(使用MaterializeCss选择选项)_Reactjs_Redux_React Redux - Fatal编程技术网

Reactjs React不在redux存储更改时重新呈现映射函数(使用MaterializeCss选择选项)

Reactjs React不在redux存储更改时重新呈现映射函数(使用MaterializeCss选择选项),reactjs,redux,react-redux,Reactjs,Redux,React Redux,redux状态更改时不重新渲染 当我进入这个页面时,最初redux商店的客户是空的。它获取数据,更新redux,但是没有被重新呈现的部分代码是select选项。尽管redux存储被更新,它只保留加载选项 以下是相关代码,尽我所能简化 class AddLoad extends Component { render(){ const customers = this.props.customers return( <Field> <

redux状态更改时不重新渲染

当我进入这个页面时,最初redux商店的客户是空的。它获取数据,更新redux,但是没有被重新呈现的部分代码是select选项。尽管redux存储被更新,它只保留加载选项

以下是相关代码,尽我所能简化

class AddLoad extends Component {

render(){
           const customers = this.props.customers
return(  
    <Field>
       <option value="" disabled selected>State</option>
                {customers.length !== 0 ? (
              <option>Loading..</option>
            ) : (
              customers.map(customer => {
                return (
                  <option key={customer.id} value={customer.id}>
                    {customer.customer_name}
                  </option>
                );
              })
            )}
          </Field>
)}
}
function mapStatetoProps(state) {
  return {
    customers: state.customers.customers,
  };
}
export default reduxForm({
  form: "PostsNewForm"
})(
  connect(
    mapStatetoProps,
    { createLoad, fetchCustomers }
  )(AddLoad)
);
我在返回中使用了一个简单的h1标记来测试这一点,出于某种原因,它工作得很好,但是映射不会再次发生

  <h1>{customers.length !== 0 ? customers[0].customer_name : "Testing"}</h1>
编辑:除了customers.length.上的逻辑错误之外,我没有提到我正在为此选择选项使用MaterializeCss,最后,逻辑修复+组件更新重新初始化Materialize解决了这个问题。

检查您的逻辑

你已经编码了

{customers.length!==0?正在加载

这意味着如果长度大于零,则呈现加载

render(){
const customers = this.props.customers

if(!customers.length){
 return Loading
}

return(  
    <Field>
       <option value="" disabled selected>State</option>
            customers.map(customer => {
                return (
                  <option key={customer.id} value={customer.id}>
                    {customer.customer_name}
                  </option>
                );
              })
            )}
          </Field>
     )}

如果您想将加载呈现为字段选项,只需更改条件。希望能对您有所帮助

我尝试了很多不同的方法,因此错过了这一部分,谢谢。