gpt4 book ai didi

javascript - react : Modal containing form won't recognise a a prop of type function being passed down to it

转载 作者:行者123 更新时间:2023-12-02 22:23:44 25 4
gpt4 key购买 nike

这是一个非常具体的问题,我已经在这个网站和网络上搜索了几个小时试图解决它。模组请不要在未完全阅读之前禁用这篇文章。我可以通过函数来​​轻松控制状态。我可以轻松地将对象数组传递给模态

此问题具体是将函数传递给包含注册表单的模式 - 完成表单后我想更改状态。

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 在各方面都完美工作 - 异常(exception)是该函数不会通过

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))
...
}

控制台.log =

props for ModalAddUser: {"aprop":"works fine"}

最佳答案

JSON.stringify 不会序列化函数。如果你尝试 console.log(props) 你应该看到你的函数。

enter image description here

关于javascript - react : Modal containing form won't recognise a a prop of type function being passed down to it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59132590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com