Hi I've been trying to make a higher order component that adds some state and event listeners to the provided component, so that I can animate them on click/touch via JS. I think I'm pretty far off, it's been a long day so excuse me if this code is nonsense.
import React, { useEffect, useState } from 'react'
const TouchAnimator = (child) => {
const [animated, setAnimated] = useState(false);
const [NewComponent, setNewComponent] = useState(child)
const handleMouseDown = () => {
setAnimated(true)
}
const handleMouseUp = () => {
setAnimated(false)
}
useEffect(() => {
setNewComponent(React.cloneElement(child, {animated: animated}));
}, [animated, child])
return (
<NewComponent onMouseUp={handleMouseUp} onMouseDown={handleMouseDown}/>
)
}
export default TouchAnimator
I'm getting an error saying: "Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: <campsite-creatorstyles__CCImageInput />. Did you accidentally export a JSX literal instead of a component?"
Can anyone help me make this work?