react_vue_ts icon indicating copy to clipboard operation
react_vue_ts copied to clipboard

Trying to set default value for useState in React from another component.

Open strikerkenpo opened this issue 2 years ago • 1 comments
trafficstars

I am passing a value from one component to another in React. Creating a updatable table from APIs on Database. The code will recognise the values in the new form when edit button is clicked, but when I try to pass them into the useState it is blank.

Here is where I passed them into new component:

export const EditEmployee=({open,onClose,empName,dep,Doj,Mail,ID})=>{

const[employeename, setemployeename] = useState('') 
const[department, setdepartment] = useState('')
const[mail, setmail] = useState('')
const[doj, setdoj]= useState('')

I have tried setting useState to the variable, but it does not read it.

Here I set the default value on form and it reads it just fine.

setemployeename(e.target.value)}/>

Can this be done like I'm wanting to do this?

strikerkenpo avatar Sep 19 '23 00:09 strikerkenpo

This is weird. I was able to use useState without any problem. It is hard for me to understand your setup to figure out the issue. Could you provide me with a simple example where this is the case?

tachyon-ops avatar Nov 27 '23 08:11 tachyon-ops