Hrmm yeah, using cloneElement with typescript is really messy. I honestly don't have a great solution to this. If I'm forced to use cloneElement I tend to make the cloned values optional, and then throw an error if they aren't actually passed to the child.
Lately I've been preferring to use React.createContext and React.useContext where possible instead, since this gets around the typing issues.
If you do find a better way of typing using cloneElement, let me know!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hrmm yeah, using cloneElement with typescript is really messy. I honestly don't have a great solution to this. If I'm forced to use cloneElement I tend to make the cloned values optional, and then throw an error if they aren't actually passed to the child.
Lately I've been preferring to use
React.createContext
andReact.useContext
where possible instead, since this gets around the typing issues.If you do find a better way of typing using cloneElement, let me know!