Skip to content

Can't call setState on a component that is not yet mounted. #92

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
samlovescoding opened this issue Aug 20, 2020 · 3 comments
Closed

Can't call setState on a component that is not yet mounted. #92

samlovescoding opened this issue Aug 20, 2020 · 3 comments

Comments

@samlovescoding
Copy link

samlovescoding commented Aug 20, 2020

I am receiving 'Can't call setState on a component that is not yet mounted.' from Chrome Console when I try to use React Form Builder.

import React from "react";
import Dashboard from "../layouts/Dashboard";
import { ReactFormBuilder } from "react-form-builder2";
import "react-form-builder2/dist/app.css";

function ApplicationBuilder() {
return (
<Dashboard>
<h1>Application Builder</h1>
<ReactFormBuilder />
</Dashboard>
);
}

export default ApplicationBuilder;

Here is the complete error.

index.js:1 Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to this.statedirectly or define astate = {}; class property with the desired state in the Toolbar component. in Preview (created by ReactFormBuilder) in div (created by ReactFormBuilder) in div (created by ReactFormBuilder) in div (created by ReactFormBuilder) in Unknown (created by ReactFormBuilder) in ReactFormBuilder (at ApplicationBuilder.js:11) in div (at Dashboard.js:16) in div (at Dashboard.js:13) in div (at Dashboard.js:12) in div (at Dashboard.js:9) in Dashboard (at ApplicationBuilder.js:8) in ApplicationBuilder (created by Context.Consumer) in Route (at App.js:12) in Switch (at App.js:10) in Router (created by BrowserRouter) in BrowserRouter (at App.js:9) in App (at src/index.js:8) in StrictMode (at src/index.js:7)

@Kiho
Copy link
Owner

Kiho commented Aug 20, 2020

I am not sure where to look at it. I can't see the warning myself.

@samlovescoding
Copy link
Author

I think this is the warning.

Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to this.statedirectly or define astate = {}; class property with the desired state in the Toolbar component.

@RoosterH
Copy link

Please read this that explains what the warning message is and how to fix it.
https://www.debuggr.io/react-update-unmounted-component/#:~:text=Warning%3A%20Can't%20perform%20a,in%20a%20useEffect%20cleanup%20function.

If you are using components instead of class, useEffect can be used.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants