[react] PropTypes 筆記
Array
Array of Object
// 包含許多物件的陣列
FooList.propTypes = {
todos: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
completed: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired,
}).isRequired,
).isRequired,
onTodoClick: PropTypes.func.isRequired,
};
Function
Foo.propTypes = {
onClick: PropTypes.func.isRequire,
};
React Elements
Children
Foo.propTypes = {
children: PropTypes.node.isRequired,
};