I have a functional react component. It does not use any props, it just return elements. Have I pass props to it anyway? Are there any agreements about that? Will be code below valid React code?
const HelloComponent = () => (
<div>Hi!</div>
);
No you don't. props
are explicitly passed to each component. If you don't use any property
from it, just don't declare it. Exactly like in your example. Consider the following
const App = () => <Child />
const Child = props => {
console.log(props) // { }
return <div>hey</div>
}
In this case props
is just an empty Object
and there is no need to declare the argument
. If you don't need to read from it, don't even mention it
const Child = () => <div>hey</div>
It is completly valid, there is no need for props. Its the same as with any other function, if it doesnt have arguments, dont give it any. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With