反应:包含模态的形式将无法识别传递给它的类型函数的道具

问题描述 投票:0回答:1

这是一个非常具体的问题,我已经在这个网站和网络上搜索了数小时来尝试解决它。 Mod请不要在没有阅读完的情况下禁用此帖子。我可以通过功能轻松控制状态。我可以轻松地将对象数组传递给模态

此问题专门将函数传递给包含注册表单的模式-完成表单后,我要更改状态。

class Users extends Component {

  aPropVal = 'works fine';

  // passing the following function as prop to any other (non-modal) component works fine
  addUserStart = (data) => {
    console.log('addUserStart has been fired')
  }

  render() {
    return (
      <div id="main">
          <ModalAddUser  addUserStart={this.addUserStart} aprop={this.aPropVal} />
...
      </div>
    )
  }
}

导出默认用户

然后,ModalAddUserObject可以在各种方式下完美运行-异常是该函数无法通过

import React, { useState } from 'react';
import { Button,  FormGroup, Input, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';

    const ModalAddUser = (props) => {

        console.log('props for ModalAddUser: ' + JSON.stringify(props))
    ...
    }

console.log =

ModalAddUser的道具:{“ aprop”:“效果很好”}

javascript reactjs bootstrap-4 reactstrap
1个回答
0
投票

JSON.stringify不会序列化函数。如果您尝试使用console.log(props),应该会看到您的功能。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.