Answer the question
In order to leave comments, you need to log in
How to pass an object to a function in React?
Hi guys, I ran into such a problem:
For example, there is an object
let user = {
age: 22,
name: 'Boris'
}
user.age
to a function to use it as a parameter in the future?// здесь передаем
let getUserData = () => {
getUserParams(user.age)
}
// тут получаем как параметр
let getUserParams = (age) => {
// используем параметр
}
user.age === undefined
// component
const UserComponent = ({user}) => {
// вызываем здесь console.log(user.age) === 22
let getUserData = () => {
getUserParams(user.age) // если вызвать console.log(user.age) здесь то === андефайнед
}
return(
//code
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question