我是反应js的新手。最近我浏览了 react js文档和 react-pos文档。我已经实现了以下代码段。但是当我运行它时,它在浏览器中没有任何影响。我哪里错了?
<html>
<head>
<style>
.box{
background:red;
}
</style>
</head>
<body>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js">
</script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js">
</script>
<script src="https://unpkg.com/react-pose/dist/react-pose.js"></script>
<div style="width:200px; height:200px; background:#eaeaea;" id="root"></div>
<script>
const Box = posed.div({
hidden: { opacity: 0 },
visible: { opacity: 1 }
});
class Example extends React.Component {
state = { isVisible: true };
componentDidMount() {
setInterval(() => {
this.setState({ isVisible: !this.state.isVisible });
}, 1000);
}
render() {
const { isVisible } = this.state;
return <Box className="box" pose={isVisible ? 'visible' : 'hidden'}
/>;
}
}
ReactDOM.render(<Example/>, document.getElementById('root'));
</script>
</body>
</html>