Created
November 24, 2020 10:24
-
-
Save equinusocio/0124f27371b190b58a98789182006644 to your computer and use it in GitHub Desktop.
React - Add attribute to componente inside prop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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