I'm trying to trigger a button to bounce when button is clicked and I'm trying to overcome a few things mentioned below:
- How do I stop useSpring to only execute when click = true (also on load)? A follow up question for this is. true is temporary how can I make it so that it reverts back to false after the animation is done or after x ms.
- How do I stop it from executing animation everytime useState() changes in Input?
- How to improve animation bounce to look more smooth? (optional)
export default function App() {
const [click, setClick] = useState(false);
const [input, setInput] = useState("");
const clicked = useSpring({
to: [{ transform: "scale(0.95)" }, { transform: "scale(1)" }],
from: { transform: "scale(1)" },
config: {
mass: 1,
tension: 1000,
friction: 13
}
});
const getInput = e => {
setInput(e.target.value);
};
return (
<div className="App">
<Input placeholder="type here" onChange={getInput} />
<animated.div style={clicked}>
<Button style={{ width: "300px" }} onClick={() => setClick(true)}>
Click me
</Button>
</animated.div>
</div>
);
}