I am working on some code, and I am stuck on this error. I am using the useState hook when a condition is true, I want to change value & show that value in Input box I get the following error: Uncaught TypeError: Assignment to constant variable. I understand that it if you define it as const you cant change its value, but I don't get why.
import React, { useState } from 'react';
const Demo = props=> {
const [userId, setUserid] = useState('abc1@gmail.com');
if (regionData === 'us')) {
userId = 'abc2@gmail.com';
} else {
userId = 'abc3@gmail.com';
}
return (
<div className="col-sm-8">
<input type="text" className="form-control rounded-10" value={userId} name="userid" onChange={(e) => { setUserid(e.target.value); }} />
</div>
)
}
export default Demo;
Any suggestions or advice is greatly appreciated.