gpt4 book ai didi

javascript - 如何解决警告 : React does not recognize the X prop on a DOM element

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:36 26 4
gpt4 key购买 nike

我正在使用一个叫做 react-firebase-js 的东西处理 firebase 身份验证,但我对 react 和提供者-消费者想法的理解是有限的。

我从在顶层构建了一个非常大的 JSX 东西开始,它在没有警告的情况下工作。但是当我尝试将它分解成组件时,我收到了标题中显示的警告和其他一些警告。

这在没有警告的情况下工作......

// in App.js component

render() {
return (
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<FirebaseAuthConsumer>
{({ isSignedIn, user, providerId }) => {
if (isSignedIn) {
return (
// ui for signed in user
);
} else {
if (this.state.confirmationResult) {
return (
// ui to get a phone number sign in
);
} else {
return (
// ui to verify sms code that was sent
);
}
}
}}
</FirebaseAuthConsumer>
</header>
);
}

但我认为这种更好的设计会产生错误/警告...

// in App.js component
render() {
return (
<MuiThemeProvider>
<FirebaseAuthProvider {...config} firebase={firebase}>
<div className="App">
<IfFirebaseAuthed>
<p>You're authed buddy</p>
<RaisedButton label="Sign Out" onClick={this.signOutClick} />
</IfFirebaseAuthed>
<IfFirebaseUnAuthed>
<Authenticater /> // <-- this is the new component
</IfFirebaseUnAuthed>
</div>
</FirebaseAuthProvider>
</MuiThemeProvider>
);
}

// in my brand new Authenticator component...

render() {
return (
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<FirebaseAuthConsumer>
{({ isSignedIn, user, providerId }) => {
if (isSignedIn) {
return (
<div>
<pre style={{ height: 300, overflow: "auto" }}>
{JSON.stringify({ isSignedIn, user, providerId }, null, 2)}
</pre>
</div>
);
} else {
if (this.state.confirmationResult) {
return (
// ui to get a phone number sign in
);
} else {
return (
// ui to verify an sms code that was sent
);
}
}
}}
</FirebaseAuthConsumer>
</header>
);
}

错误/警告看起来像这样......

[Error] Warning: React does not recognize the isSignedIn prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase issignedin instead. If you accidentally passed it from a parent component, remove it from the DOM element.

[Error] Warning: React does not recognize the providerId prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase providerid instead. If you accidentally passed it from a parent component, remove it from the DOM element.

[Error] Error: Unable to load external reCAPTCHA dependencies! (anonymous function) (0.chunk.js:1216) [Error] Error: The error you provided does not contain a stack trace.

是我误解了如何使用提供者-消费者,还是 react-firebase 代码有错误,还是我做错了什么?谢谢。

最佳答案

据推测,这一行一定是罪魁祸首:

<FirebaseAuthProvider {...config} firebase={firebase}>

您的 config 对象当前包含字段 isSignedInproviderId,您必须将它们发送到子组件,并最终发送到 DOM元素。在发送之前尝试从对象中删除这些字段:

const { providerId, isSignedIn, ...authProviderConfig } = config

这样,您的对象 authProviderConfig 将不会包含 providerIdisSignedIn 属性。

更好的是,您可以显式重建配置对象以避免任何进一步的混淆:

const authProviderConfig = { /* The fields from config FirebaseAuthProvider actually needs */ }

您还应该检查您的 FirebaseAuthProvider 组件以了解它如何使用这些 Prop ,并避免将它们传播到 DOM 元素。

相关文档:https://reactjs.org/warnings/unknown-prop.html

关于javascript - 如何解决警告 : React does not recognize the X prop on a DOM element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54468535/

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