-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[bug]: Animated div typescript error regarding children prop #2358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
2025/2/25。I encountered the same bug
error
|
I have a temporary solution.
This eliminates type errors, but I don't know if it will cause other type problems, so use caution |
Having the same issue here. import reactSpring from "@react-spring/web";
declare module "@react-spring/web" {
const animated = {
children: React.ReactNode,
...reactSpring.animated,
};
} |
Having same issue |
I haven't checked in previous version, but the workaround below has worked in the latest.
export default function App() {
const [open, toggle] = useState(false)
const [ref, { width }] = useMeasure()
const props = useSpring({ width: open ? width : 0 })
// ↓workaround
const AnimatedDivFill = animated("div")
const AnimatedDivContent = animated("div")
// ↑
return (
<div className={styles.container}>
<div ref={ref} className={styles.main} onClick={() => toggle(!open)}>
<AnimatedDivFill className={styles.fill} style={props} />
<AnimatedDivContent className={styles.content}>{props.width.to(x => x.toFixed(0))}</AnimatedDivContent>
</div>
</div>
)
} |
this is issue is only a type issue. Dont modify your code patterns for it. Just override the type like I did in my post above. |
…ror (pmndrs#2358) React 19 moved the JSX namespace from global scope to the React module. This updates type definitions to explicitly import the `JSX` type from 'react', resolving issues issues for consumers using React 19+. Note: Backwards-compatible with React 18.
Which react-spring target are you using?
@react-spring/web
@react-spring/three
@react-spring/native
@react-spring/konva
@react-spring/zdog
What version of react-spring are you using?
9.7.5
What's Wrong?
Animated tags don't seem to support children prop for TypeScript. This seems similar to issue #2332, but I'm not using Next 15/React 19, I am currently using Next 14.2.24 and React 18.3.1.
The animated.div only has an SVG (made React component by SVGR) as a child. While I was able to get around the issue by using the animated function instead and passing a component in there (i.e. see second image, there are no typescript errors present there), I'm sure there would be situations where having animated.div take children would be preferable compared to defining a component separately.
To Reproduce
Use an animated tag with children elements
Expected Behaviour
No Typescript issue
Link to repo
No public repo currently
The text was updated successfully, but these errors were encountered: