Lai32290 Lai32290 - 1 year ago 118
Javascript Question

How to React component extend all passed properties?

When I creating a

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
extends all I passing properties?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download