在 ReactJS 中传递道具并且它们不会加载,同时收到目标容器错误?

Passing props through in ReactJS and they won't load, while receiving a target container error?

希望有人可以阐明我最近 运行 遇到的问题。我正在尝试为某人创建一个登陆页面来编辑一些个人资料信息(用户名、电子邮件等)。问题是当我将道具从一个函数传递到另一个函数时,它们加载为未定义。相关代码如下...

class ChangeFields extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            user: [
                {
                    username: "test"
                }
            ]
        }
    }
    render() {
        const formSample = (
            <div>
                <h3>Account Information:</h3>
                <br></br>
                <CurrentInfo user={this.state.user} onItemSelect={this.updateInfo()} />
            </div>
        );
        return formSample;
    }
}

const CurrentInfo = ({user, onItemSelect}) => {
    console.log(user.username);
    const formElement = (
        <Form horizontal>
            <FormGroup controlId="formHorizontalUsername">
                <Col componentClass={ControlLabel} sm={2}>
                    {user.username}
                </Col>
                <Col sm={10} value={user.username}>
                    <FormControl controlId="testControl" value={user.username} />
                </Col>
            </FormGroup>
        </Form>
    );
    return formElement;
};

不幸的是,CurrentInfo 块中的 "user.username" 输出为未定义。有什么见解吗?注意:这是一个简化版的代码,如果需要更多我可以提供。

同样值得注意的是,我收到以下警告:未捕获错误:_registerComponent(...):目标容器不是 DOM 元素。

我曾尝试将 index.html 中的行移到底部,正如其他人所建议的那样,但这并不能解决问题。

Unfortunately, the "user.username" in the CurrentInfo block outputs as undefined. Any insight?

这个:

this.state = {
            user: [
                {
                    username: "test"
                }
            ]
        }

应该是:

this.state = {user: {username: "test"}};

您当前正在将 user 属性 设置为数组。

It is also worth noting, that I receive a warning of: Uncaught Error: _registerComponent(...): Target container is not a DOM element.

这可能发生在不在您问题中的代码中。