Javascript React:包含形式won'的模态;无法识别传递给它的函数类型的属性
这是一个非常具体的问题,我在这个网站和网络上搜索了几个小时试图解决它。Mod请不要在没有完全阅读的情况下禁用此帖子。 我可以通过函数轻松控制状态。 我可以轻松地将对象数组传递给模态 这个问题特别是将一个函数传递给一个包含注册表单的模态-在完成表单后,我想更改状态Javascript React:包含形式won'的模态;无法识别传递给它的函数类型的属性,javascript,reactjs,bootstrap-4,reactstrap,Javascript,Reactjs,Bootstrap 4,Reactstrap,这是一个非常具体的问题,我在这个网站和网络上搜索了几个小时试图解决它。Mod请不要在没有完全阅读的情况下禁用此帖子。 我可以通过函数轻松控制状态。 我可以轻松地将对象数组传递给模态 这个问题特别是将一个函数传递给一个包含注册表单的模态-在完成表单后,我想更改状态 class Users extends Component { aPropVal = 'works fine'; // passing the following function as prop to any other
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>
)
}
}
console.log=
ModalAddUser的道具:{“aprop”:“工作正常”}
stringify不会序列化函数。如果您尝试console.log(props),您应该会看到您的函数
如果可能的话,请发布一个指向codesandbox.io的链接。这里有一个指向code sandbox的链接,而且它似乎工作正常。。谢谢-我必须假设其他一些元素(包含的库或脚本错误在运行时未显示)是限制因素。请让我花点时间在沙盒上发布更多的代码。我已经发布了答案。你是对的,我为这一疏忽感到抱歉。它不是因为其他原因发射的,但事实上它是通过的。谢谢你提供了另一副眼睛-这是一件非常简单的事情,但我没有看到。不用担心,很乐意帮忙。最简单的bug有时更难捕获:)
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))
...
}