Feel free to play or contact me!
old-fashionedfolder, you can just open thehtmlfile in the browser and everything should be fine.webpack-framefolders, you needcdinto one of them andnpm installthennpm run dev, everything should be fine. Though thedevcommand is kind of tricky because I keep the dist folder rather than a singleindex.htmloutside the dist folder, anthor thing to tackle.- If you want to
npm run build, at this moment(20/09/2017), I don't know the exact way how the webpack working. Cleaning the dist folder is kind of beyond me.
After a long time, I turn back to ReactJS. So I have to learn a lot of things from very start.
Many of them are from the official documentation examples.
- create
package.jsonvianpm init. - create
webpack.config.js, configuring the basic config.- devServer, an amazing package,
npm install --save-dev webpack-dev-server babel-loaderfor js, choose the suitable preset, in this case,latest, stage-0, react.json-loaderfor json, for mocking some simple json data.style-loader!css-loader!autoprefixer-loaderfor css.style-loader!css-loader!autoprefixer-loader!sass-loaderfor sass, you may need installnode-sassas well.
- devServer, an amazing package,
- create some npm command in the
package.json.
And then you are free to fly!
Classshould be name with PascalCase rather than camelCase or kabab-case.- Several ways to create
Component,createReactClass/extends React.Component/stateless functional Components. It is a good way to usestateless functional Componentswhich might have better performance. react-iconsis an awesome icons library.prop-typeshas been moved out of theReactpackage to another individual package. See this. It is not compulsory.react-router, something useful is in thehistorypackage.Linkis in thereact-router-dompackage, maybe you need to install manually.setStateis used to set some data to the component's state, rather than just give an assignment statement.- in
Visual Studio Code, add"files.associations": { "*.js": "javascriptreact" }to use the jsx syntax in react-related-js files. - you cannot return false to prevent default behavior in React. You must call preventDefault explicitly.
- Using Typescript with Creat React App, just run
creat-react-app my-app --script-version=react-scripts-ts. Formatting Code Automatically, read this article.