i am using javascript
destructuring like this will pick properties from the incoming argument object
export default function App() {
const data={name:"name",age:"age"}
return(
<>
<SHow data={data}/>
</>
)}
////eslint error 'age' is missing in props validationeslintreact/prop-types (parameter) age: any
function SHow({name,age}) {**/////eslint error 'age' and 'age' is missing in props**
return(
<>
<h1>{name}</h1>
<h1>{age}</h1>
</>
)}
the code is working properly
so why es lint showing /////eslint error ‘age’ and ‘age’ is missing in props
i tryed this but i don’t want create new variable for each component
function SHow(prop) {
**const {name,age} =prop**
return(
<>
<h1>{name}</h1>
<h1>{age}</h1>
</>
)}
2
Answers
The issue is you’re only passing a single prop named
data
with the original.Try either spreading the props
which is the equivalent of
or destructuring the
data
propThe prop you are passing is data. Try this :