How could I pass/access the props of an imported component? This example component comes from a third-party library, so I'm not sure how I'd go about getting its props
import { Example } from './comps'
const App = () => {
return (
<Example />
);
console.log(Example.props) //this returns undefined
}
export default App;
You cannot access props of a child Component from parent Component in that way.
Moreover:
const App = () => {
return ( // return will finish the function, so the console.log below doesn't make any sense.
<Example />
);
console.log(Example.props) //this returns undefined
}
In your example, props is the things passed from App
, so you can pass/access directly from App
:
const App = () => {
const [value, setValue] = useState(0);
return (
<Example number={value} setNumber={setValue} />
);
}