score:0

you don't really need init, that is what the constructor is for. you should pass in the text as a prop to component b when you create it:

import b from 'b.js';

class a extends component {
    componentdidmount() {
        const b = new b({ initialtext: 'hey' });
    }
}

then you can set the state inside the constructor for b.

state = {
    text: prop.initialtext,
};

be careful though, setting the state from a prop is generally a bad idea. see the note block here https://reactjs.org/docs/react-component.html#constructor for more details.


Related Query

More Query from same tag