是否有任何简短的命令将模块移动devDependencies
到dependencies
package.json中?
我发现自己总是这样做:
npm uninstall <module_name> --save-dev
npm install <module_name> --save
Run Code Online (Sandbox Code Playgroud)
有没有更简短的方法?
我有一个<Child />
组件列表,然后我使用一个数组this.state.infos
来生成这些子组件。如何使用this.refs
来获取特定的子组件?
注意:this.state.infos = ['tom', 'mike', 'julie'];
例如。
export default class Parent extends React.Component {
constructor(props) {
super(props);
this.state = {
infos: {},
};
}
// ignore logic for this.state.infos
// ...
render() {
return (
<div>
{[...this.state.infos].map((info) => {
return <Child
ref={info}
/>
})}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud) 我PureComponent
在我的 React 应用程序中使用它以获得更好的性能,props
但我不希望它在props
更改时运行渲染方法。我知道我们不能使用shouldComponentUpdate
inReact.PureComponent
但我的问题是:
有什么办法可以避免更新React.PureComponent
吗?
我希望这个组件根本不更新/渲染。
编辑:shouldComponentUpdate
在 pureComponent 中使用时收到此警告:
警告:GameObjectFall 有一个名为 shouldComponentUpdate() 的方法。扩展 React.PureComponent 时不应使用 shouldComponentUpdate。如果使用了 shouldComponentUpdate,请扩展 React.Component。
我有与创建的应用程序React 16.3.X
,需要this.props
在getDerivedStateFromProps()
方法。
例如:
static getDerivedStateFromProps(nextProps, prevState) {
console.log(this.props); // `this` is not defined
if (nextProps.id !== this.props.id) {
// do something...
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
显然this
未在规定static
的方法,但我需要知道的是有没有办法让this.props
在getDerivedStateFromProps()
?