Lai32290 Lai32290 - 12 days ago 4
Javascript Question

How to React component extend all passed properties?

When I creating a

React
like following component:

class UploadInput extends React.Component {
render() {
return (
<input type="file" {}/>
);
}
}


When I using:

<UploadInput anyProp="value" />


How to can I make for
UploadInput
extends all I passing properties?

Answer

If I understand you correctly what you want is when you do this:

<UploadInput type="text" name="some name" value="some value" ... />

you need input inside UploadInput to be rendered like this:

<input type="text" name="some name" value="some value" ... />

Solution: You can use JSX Spread operator for that:

<input {...this.props} />

Whatever props you are passing to UploadInput component will be passed down to input as well.

Comments