I know you can pass plain objects and arrays in react props easily.
But my question is if its possible to pass a class object as well?
I mean, I have this class:
class Something {
constructor() {//data}
method() {...}
etc...
}
now I want to pass that object as a prop:
let sm1 = new Something();
<Component item={sm1} />
if you wonder why is simply because I have a big array of specific rules that I easily use the rules inside that class.
A class
is an object
in JavaScript and it makes no difference if you pass a class, an object or an array. You can pass the class instance without having any side-effects. Its just like a passing a function as a prop
let sm1 = new Something();
<Component item={sm1} />
would be similar to
<Component handleChange={this.handleChange} />
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