const App = ({todos, actions}) => ( <div>
<Header addTodo={actions.addTodo} aaa/>
<MainSection todos={todos} actions={actions} />
</div>)這是父組件,里面有個Header是自定義組件,其中有個自定義屬性是aaa.這個aaa是我隨手寫的,也未在其他地方聲明過。然后我在Header里面,console.log出aaa,為啥是個true?export default class Header extends Component {
static propTypes = {
addTodo: PropTypes.func.isRequired
}
render() {
console.log(this.props)//值為Object {aaa: true}
return (
<header className="header">
<h1>todos</h1>
<TodoTextInput newTodo
placeholder="What needs to be done?" />
</header>
)
}
}
為什么React props 的默認值會是 true ?
郎朗坤
2018-10-02 12:25:53