react will component update code example

Example 1: react native class component constructor

import React from 'react';  
import { View, TextInput } from "react-native";

class App extends React.Component {  
  constructor(props){  
    super(props);  
    this.state = {  
         name: "" 
      }  
    this.handleChange = this.handleChange.bind(this);  
  }
  handleChange(text){
    this.setState({ name: text })
    console.log(this.props);  
  }  
  render() {  
    return (  
    
      this.handleChange(text)}
      />
      
  }  
}  
export default App;

Example 2: react lifecycle hooks

class ActivityItem extends React.Component {
  render() {
    const { activity } = this.props;

    return (
      
avatar
{moment(activity.created_at).fromNow()}

{activity.actor.display_login} {activity.payload.action}

{activity.repo.name}
) } }

Tags:

Misc Example