Skip to content

Instantly share code, notes, and snippets.

@sheronw
Last active June 12, 2020 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheronw/9981f3e6f40cd2b4b06ff08342eb5ca1 to your computer and use it in GitHub Desktop.
Save sheronw/9981f3e6f40cd2b4b06ff08342eb5ca1 to your computer and use it in GitHub Desktop.
set up #react
import PropTypes from 'prop-types';
class App extends Component {...
getSth(){ return this.xxx; } // getSth = () => this.xxx;
render() {
return (<p>{this.getSth().bind(this)}</p>)
}
}
App.propTypes = { a:PropTypes.array.isRequired }
export default App;

使用 create-react-app 构建环境(官方推荐使用npx)

npx create-react-app my-app
cd my-app
npx -p @storybook/cli sb init # 添加storybook
npm start

过了一遍官方教程,随便写点笔记如下:

  • parent component to child component: props
  • child component to parent component: callback function
  • state 尽可能放 parent component,如果一个 component 没有 state 可以定义为 function
  • 推荐使用immutable state,便于比对是否需要re-render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment