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]);

Related Query

More Query from same tag