I am using a 'this.state' variable to hold a bool, until a function is triggred, this has been working fine with my websites up until now.
my constructer, and the function to trigger the error will be left below as well as the line with the error.
The error is being triggered on all the classes that use the same code,
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
toDashboard: false,
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
//see update for new handleLogin() function
render() {
if (this.state.toDashboard === true) {
return <Redirect to='/dashboard' />
}
}
This is how invoke handleLogin():
handleSubmit = (e) => {
e.preventDefault();
const form = {
password: this.state.password,
email: this.state.email
}
this.handleLogin(form)
}
update: I have change my function to an arrow function like this and are still getting the same error:
handleLogin = (form) => {
const email = form['email']
const password = form['password']
fire.auth().signInWithEmailAndPassword(email, password).catch(function (error) {
var errorMessage = error.message
console.log(errorMessage)
});
fire.auth().onAuthStateChanged( user => {
if (user) {
console.log(user)
//error happens here
this.setState({ toDashboard: true })
} else {
// No user is signed in.
}
});
}
error:
Uncaught (in promise) TypeError: Cannot add property updater, object is not extensible
at adoptClassInstance (react-dom.development.js:12821)
at constructClassInstance (react-dom.development.js:12882)
at updateClassComponent (react-dom.development.js:17100)
at beginWork (react-dom.development.js:18620)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at beginWork$1 (react-dom.development.js:23203)
at performUnitOfWork (react-dom.development.js:22157)
at workLoopSync (react-dom.development.js:22130)
at performSyncWorkOnRoot (react-dom.development.js:21756)
at react-dom.development.js:11089
at unstable_runWithPriority (scheduler.development.js:653)
at runWithPriority$1 (react-dom.development.js:11039)
at flushSyncCallbackQueueImpl (react-dom.development.js:11084)
at flushSyncCallbackQueue (react-dom.development.js:11072)
at scheduleUpdateOnFiber (react-dom.development.js:21199)
at Object.enqueueSetState (react-dom.development.js:12639)
at LoginForm.push../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:471)
at loginform.js:31
at auth.esm.js:389
GitHub repo is here if you want to see all the files: https://github.com/lukeacko12/tikkr
thisClone = this?Unhandled Rejection (TypeError): Cannot read property 'setState' of undefined, that happens if i dont usethis clone = thisthisin local varhandleLogin@LukeAcko13