跳到主要内容

React Live

import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live';

const Live = () => {
return (
<LiveProvider code="<strong>Hello World!</strong>">
<LiveEditor />
<LiveError />
<LivePreview />
</LiveProvider>
);
};
  • noInline - 不做 render 封装 - 可以在代码里调 render 方法
  • scope - 传递上下文
function Clock(props) {
const [date, setDate] = useState(new Date());
useEffect(() => {
const timerID = setInterval(() => tick(), 1000);

return function cleanup() {
clearInterval(timerID);
};
});

function tick() {
setDate(new Date());
}

return (
<div>
<h2>It is {date.toLocaleTimeString()}.</h2>
</div>
);
}