Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  28] [ 3]  / answers: 1 / hits: 7638  / 2 Years ago, tue, march 15, 2022, 12:00:00

The solutions provided when doing my research are based on React class and not React function and I'm just a newbie in React.


From the parent component I'm calling the child component and passing the values as 'data'. In the child component I'm retrieving the value using props.


ParentComponent.js


<ChildComponent data={1}/>

ChildComponent.js


function ChildComponent(props) {
const { data } = props.data;
...
}

The above gives me the following error message:



srccomponentsChildComponentChildComponent.js Line 5:11:
'data.data' is missing in props validation react/prop-types Line
5:29: 'data' is missing in props validation react/prop-types


Search for the keywords to learn more about each error.



More From » reactjs

 Answers
13

@Denno and @Nick Vu is correct but there might be something else you'll have to add to your child component just before the export.


ChildComponent.propTypes = {
data: PropTypes.object
};

and add import


import PropTypes from "prop-types";

and change this


function ChildComponent(props) {
const { data } = props.data;
...
}

to


function ChildComponent(props) {
const data = props.data;
...
}

[#280] Thursday, March 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nadiatristinl

Total Points: 151
Total Questions: 116
Total Answers: 108

Location: Japan
Member since Tue, Jul 26, 2022
2 Years ago
;