Simple display of component life cycle in React-webpack,react

Source: Internet
Author: User

First configure the next webpack.config.js

module.exports={    entry:{        Demo:'./app/app.js '    },    output:{        path:__dirname+ '/build ',        filename:' [name].js ',        Library:' game ',        librarytarget:' UMD '     },    module:{        loaders:[            {                test:/\.js$/,                loader:' Jsx-loader '             }        ]    }}

Import file entry, integrated JS output output,loaders: Need to Jsx-loader convert jsx to JS

Create HTML

<!DOCTYPE HTML><HTML><Head>    <MetaCharSet= "Utf-8">    <title>Title</title>    <Metaname= "keywords"content="">    <Metaname= "description"content=""></Head><Body>    <DivID= "Out"></Div></Body><Scripttype= "Text/javascript"src= "Build/demo.js"></Script></HTML>

The entry file in the above configuration file./app/app.js

To create this file first

varHead=require ('./app1.js '));varCon=require ('./app2.js '));varFooter=require ('./app3.js '));varReact=require (' React ');varReactdom=require (' React-dom ');vardemo=React.createclass ({render:function(){            return(<div> }}) Reactdom.render (<demo/>,document.getelementbyid (' out '));

Use require to import the dependencies first, then create the components with react

To create a dependent APP1,APP2,APP3 3 JS

var React=require (' React '); var head=React.createclass ({        render:function() {            return (<div>                     Head                         </div>)        }    ) module.exports=head;

Simple example creation is done, required react,react-dom,jsx-loader, we can use NPM install to create dependencies into the project.

The life cycle of a component


Getdefaultprops------>getinitialstate------>componentwillmount------>render------> Componentdidmount------> Component operation

2. During the operation

Divided into two state states and external props changes


Shouldcomponentupdate------> If true------>componentwillupdate------>render------> Componentdidupdate


Componentwillreceiveprops------>shouldcomponentupdate .....

3. Uninstalling components


Simple display of component life cycle in React-webpack,react

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.