import React,{ Component } from 'react';
class SearchBar extends Component {
constructor(props){
super(props);
this.state = {term : ''};
}
render() {
return this.setState( { term:event.target.value } )} />;
}
}
export default SearchBar;
这里的props指的是什么?怎么理解?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这是一个属性的集合,元素为当前组件的所有属性的键值对
例如你在渲染组件时使用这样语法:
那么props就是:
props不是数组,是对象。就是组件从外部获得的props,和你在其他地方写的this.props是一个东西
JSX:
JS:
placeHolder属性会传入组件的props对象内--->{placeHolder:'搜索'}