0

If you think this question is stupid, sorry for that and please forgive me because iam Beginner.:)

1) I want to declare variables using react hooks i done like this:

const[adata,setAdata]=useState(   
                    name:"",
                    companyname: ""
                  })

2)I want to assign " name" to the value(name=filteredperson.name,companyname=filteredperson.companyname) that inside map function here, map function code:

    {data.map((filteredPerson, index) => (
<td>{filteredperson.name}</td>
<td>{filteredperson.companyname}</td>

3)Finally,so i assigned my map function values to variables using react hooks, i want to print it on console.

for eg:name:{filteredperson.name} value in console

Note:filteredperson is a map function. I want to assign map values to variables that are using react hooks.

1 Answer 1

1

Your data variable is of type {name: string, companyname: string}, so to assign value to this variable, you call the setter function:

setData({name: NAME_VALUE, companyname: COMPANYNAME_VALUE})

After you set the value of this object, you can print the values with:

console.log(data.name) console.log(data.companyname)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.