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.
Source: stackoverflow.com
Related Query
- React - Calling setState in a function that's called from another class throws not a function exception
- Calling React setState from another class method doesn't update set
- In React why does calling a function from another function in our code not work and display?
- React Hooks state not working properly when the function calling it is called in another function
- Calling function in component class from Highcharts component in React
- function doesn't call from one class to another class in react js
- REACT: Use setState in a function called from another component?
- React call from class to functional component. Error: Invalid hook call. Hooks can only be called inside of the body of a function component
- Button Function Not calling From Another file in React
- Calling modular custom javascript module function twice from React component. Why is it being called twice? Scenario shown below:
- React funcional component calling function from another component
- Calling React setState from outside of function body
- Calling react hook from a function on another page
- How can I use a function from another class in my React app?
- React 'this' undefined when calling a callback function in a class from a function child component
- React ES6: calling async function from another function not defined
- How to refer to another class from a function in React JS?
- call a function from another class in react
- Calling a function in another class with react js and react-router
- How to assert a function is called from within another function?
- Call function from another React component
- Refactor a React component from function to ES6 class
- React - How do you call a function from inside another function
- React updating progress from a compute intensive function using setState
- How do I call/execute a function from another component in react native?
- Can class object be called from React Component Prop?
- Calling React Component function from JS function
- Stop an interval from another function in React
- React Hook "useState" cannot be called in a class component. React Hooks must be called in a React function component or a custom React Hook function
- React - calling function from a sibling component
More Query from same tag
- Trigger useEffect when screen dimension has changed
- How to access a function in a child class component from a stateless parent?
- reducer action is just returning pending promises
- Load content from sidebar in react
- Install local package as dependency with react-native
- Next JS Images after next build gives 404 images
- Replacing an attribute in an array exists, or adding a new attribute pair if not
- Draft-js-plugins emoji select component - close popover after select emoji
- How can I expand the option without using the arrow button in antd select?
- Local video will not load - Webpack
- How can implement react-google-maps DirectionsRenderer in my project
- update data in state array on socket event
- How to access item object outside "return" in react?
- Protect routes with React Router v6 and API Call
- React table with sorting and pagination doesn't update
- Either no field is required or all fields are required if any of the field is non-empty in yup Schema validation
- Why isn't this RequireJS shim working for react-router
- React Router v4: <Route> component unable to match urls with question marks
- Refactoring React Class component to Functional - TypeError: Cannot read properties of undefined (reading 'slice')
- Formik + Yup: How to immediately validate form before submit?
- Can't properly type the following HOC function
- Host react app and laravel backend(Admin panel) in same laravel application project
- Can home_url() be dynamically passed to a theme built with React?
- Meteor: accounts-ui Package
- Why React Component render many time when get event from socket.io?
- React-Jest Unit test an external module method that affects state
- Jest test passes but error not caught and logs to console
- why termux dont permission to create gitignore file in create-react-app
- Facebook's react.js -- object is not a function
- Problem fetching data from Axios in React