【发布时间】:2023-03-28 17:50:02
【问题描述】:
import React from 'react';
import { render } from 'react-dom';
const x = [];
const App = props => <div style={styles}>{JSON.stringify(x)}</div>;
render(<App queries={x} />, document.getElementById('root'));
setInterval(x => x.push(Math.random()), 1000, x);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
当我改变作为道具传递给它的对象时,为什么 App 组件不重新呈现。
每当我关闭并重新打开 React 开发工具时,它都会显示新的道具。
这里发生了什么?请帮我理解。
谢谢!
【问题讨论】:
-
您提供的 sn-p 实际上没有具有适当生命周期或状态管理的组件。
标签: javascript reactjs