M
M
Maksipes2019-10-24 09:21:52
React
Maksipes, 2019-10-24 09:21:52

Is it possible to pass this props?

The question of best practices is whether it is good to do so or not.
Manuals usually write like this:

<SomeComponent
    data={this.state.data}
    onDataChange={this.updateData}
    onDataDelite={this.deliteData}
 />

Sometimes you have to pass a lot of things to the component, which makes the entry very bold.
Is it possible to do so? And inside the component, do this:
<SomeComponent that={this} />
const {
    data,
    updateData,
    deliteData
} = this.props.that;

Or is it not good practice?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Proskurin, 2019-10-24
@maksipes

Not worth it. You should clearly specify the required props without passing any large config object or spread operator.
This is the API of the component, and it will be much clearer to immediately see all the fields used by the component at the place of its call. Let it look more cumbersome, but it is easier to read.

N
nivaech, 2019-10-24
@nivaech

You can use the spread operator
Look here.
https://riptutorial.com/reactjs/example/13689/pass...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question