Skip to content

Instantly share code, notes, and snippets.

@equinusocio
Created November 24, 2020 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equinusocio/0124f27371b190b58a98789182006644 to your computer and use it in GitHub Desktop.
Save equinusocio/0124f27371b190b58a98789182006644 to your computer and use it in GitHub Desktop.
React - Add attribute to componente inside prop
/* trigger is the prop that accepts a ReactNode */
const addAttr = useMemo(() => {
const InputReactObject = Children.only(trigger);
const clonedChild = cloneElement(inputReactObject, {
className: 'input-element test',
'data-attr': 'lorem'
});
return <InputReactObject />;
}, [trigger]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment