<div></div> } }); React.render(<MyComponent/>, mountNode); API React.render(ReactElement el, DOMElement container) Render “ReactElement” into DOM. Note. We can use multiple “React.render” if necessary.
<div></div> } }); Component Specifications render() Define the component will be show on web, usually using JSX to build it. Note. When we using <div> in ReactJS, it is not “real” HTML tag, it is a Component.
false }; } // Skip... }); Component Specifications getInitializeState() Component owns it state, we can use for control what we want to render. Example: We can show image only state is “Active”
isActive: true}); } // Skip... }); Component Specifications componentWillMount() The “componentWillMount()” means before it “show on DOM”, the component should do something. Note. Also have “componentDidMount()” for do something “after” show on DOM.
isActive: true}); } // Skip... }); Component API this.setState(object nextState) Update the component’s state, passing a object to override current state. Note. Change state and props will trigger “render()” to render new VDOM.
canMove: true}); } // Skip... }); Component API this.setProps(object nextProps) Update the component’s props, passing a object to override current state. Note. Strongly suggest not use this to change property, change it from it’s parent.
<div>Can I move? { this.props.canMove ? "Yes" : "No" }</div>; } }); Component API this.props All component property will store in this object, simple using “this.props.canMove” to get property.
<div>Children: { this.props.children }</div>; } }); React.render(<MyComponent><div>A</div><div>B</div></MyComponent> , mountNode); Component API this.props.children When your component will contains other component, you can access these component via this API.
<div>Current is { this.state.isActive ? "Active" : "Deactive" }</div>; } }); Component API this.state All component state will store in this object, simple using “this.state.isActive” to get state.
{ comments: (new Parse.Query('Comment')).ascending('createdAt') }; }, // Skip... }); Usage observe() ParseReact patch the origin Parse API, add “subscribe” feature and we can use “observe()” to listen change. Note. This only working on local, and reduce API request.
(<div>{this.data.comments.map( function(comment) { return comment.content}) }</div>) } }); Usage this.data After we “observe” data changed, we can fetch data via use “this.data” property which mixin defined.
content: "Hello World" }); // Execute it (Submit to Server) creator.dispatch(); Usage: Mutation ParseReact.Mutation.Create(string className, object data) ParseReact Mutation provide CRUD feature helps us interact with Parse API to modify object.
it (Submit to Server) destroyer.dispatch(); Usage: Mutation ParseReact.Mutation.Destroy(ParseObject object) If we pass a “ParseObject”, Mutation can help us destroy it. Note. When we using “observe” we already get “ParseObject” we defined.
'Aotokitsuruya' }) // Execute it (Submit to Server) changer.dispatch(); Usage: Mutation ParseReact.Mutation.Set(ParseObject object, object changes) We can use “Set” to modify object, and changes object only need pass necessary to change data.
it (Submit to Server) destroyer.dispatch(); Usage: Mutation dispatch([options]) Mutation using “Flux” style to implement, after we finished modify, we need to “dispatch” it. Note. Flux is a idea like MVC, but we have not time to talk about it.