score:1
Accepted answer
i'd suggest moving the onchange
callback logic to an useeffect
hook with a dependency on the bbcodetext
state. this way anything that updates the bbcodetext
state value will trigger the effect to invoke the onchange
handler to update anything in the parent component.
const [bbcodetext, setbbcodetext] = usestate("");
const update = (e) => {
setselection(null);
setbbcodetext(e.target.value);
}
const handleemoji = (emoji) => {
setbbcodetext(bbcodetext => bbcodetext + " " + emoji.native);
}
useeffect(() => {
if (typeof props.onchange == 'function') {
props.onchange(bbcodetext);
}
}, [bbcodetext]);
Source: stackoverflow.com
Related Query
- React + Flux: Getting initial state into a store
- React multiple instances of same component are getting same state
- React & Redux - state getting empty after route changed
- React Redux: Getting Props And Updating State
- React <Switch> is not getting updated or changing its state
- Method not getting correct useState value despite updating state in React
- Still getting "React state update on an unmounted component" error with React Testing Library tests
- Change of state is not getting affected in another unmount useEffect in react hooks
- Taking React State (object of objects(example inside)) and getting an array of objects to map() for component rendering
- Getting checkbox state in React JS
- How to fix the state update in react while getting data from firestore database
- React - ComponentDidMount not getting value from Redux state
- React State not updating and getting reset to original state
- React input value getting reset to initial state after onChange callback
- Getting latest state value with React Hook?
- React JS - getting a separate component to re-render when localStorage state is changed
- React / Redux - Getting variable to update properly on change of global state
- React Hooks Wrapper not getting updated after state change in useEffect
- Unable to pass state value through react jsx. Getting error - Unexpected token : 'this'
- Setting and getting state from session storage react
- react doesn't get re-render after getting new store state into props
- React router private route not getting props from state (e.g. authentication state)
- React State not getting updated properly in SetInterval Methods
- Input element's value in react component is not getting re-rendered when the state changes
- react array state is getting cleared before getting rendered
- Getting undefined on state when accessing from child to parent - React
- How to set defaultChecked getting value from state React Functional Component Checkbox (React - Hooks)
- State isn't getting update correctly React
- React Redux getting NaN after mapping state
- React component not getting rendered each time when state changed
More Query from same tag
- Conver myRef to hooks version
- Where is defined the default material-ui spacing?
- React Search title result and Pagination Material UI
- React Router Switch statement with routes grouped as component inside does not go to Not Found route
- Including fontawesome brand icons on frontmatter metadata
- How can I fetch data to graphql server when I want
- What is the simplest way to share react components between projects?
- Html select options from given array not showing
- react render table elements with array.map
- React - Redux Error: Element type is invalid after connect
- Can't resolve '@material-ui/lab/Slider' in {path}
- How do I fix React ' is not defined no-undef'?
- Use React hook to implement a self-increment counter
- TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'
- How can I handle an event to open a window in react js?
- react-bootstrap + purgeCss + next.js
- Updating state value on at a time using useState
- A react component is not rendered even after calling it through ReactDOM.render( ) method
- How come props doesn't show when I try to print in react
- How would you make an async/await function to show a dialog in React?
- Extend typography in Material UI theme
- What is the correct way to pass props (Vue/React)? Pass object or each prop separately?
- how could I use useEffect() in Class component?
- Array inside an Object with Dynamic Key in Redux
- Shared services between react and angular
- Bootstrap font is different in react
- React unnecessary render of element
- Is there a way to make typescript generics props not read only ?
- Sending data to mongodb realm gives 400 error
- Typescript property does not exist on extended type