0
我有一個工作的React組件,它只是顯示一個包裹在標題標籤中的小字符串。由於它是顯示正常,我幾乎肯定我的導入/導出設置正確。當我嘗試將<Spring />
組件添加到我的render()
方法中時,我得到:引起不變違規的React-Motion Spring組件
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of Animation
。
爲什麼<Spring>
組件會在一切正常工作之前發生這種情況?我下面的代碼:
import React from 'react';
import { Spring } from 'react-motion';
class Animation extends React.Component {
constructor(props){
super(props);
}
render() {
return (
<Spring defaultValue={0} endValue={120}>
{val => {
let style = {
height: val,
position: 'absolute'
}
return <div style={style}><h1>Hi!</h1></div>
}}
</Spring>
)
}
}
export default Animation;