React: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Line 33: Line 33:
     this.state = {name: "Frarthur"};
     this.state = {name: "Frarthur"};
   }
   }
render() {
  render() {
  return <div></div>;
    return <div></div>;
}   
  }   
};
};
};</source>
</source>

Revision as of 06:00, 23 October 2019

Quick Reference

Variables

 const myVar = (
   <h1>Love it</h1>
 );

Run

Maps

 // Only do this if items have no stable IDs
 
 const todo = ["fix", "syntax", "highlighting"];
 const todoItems = todos.map((todo, index) =>
 <li key={index}>
   {todo.text}
 </li>
);

Component Example

import React, {Component} from 'react';
import ReactDOM from 'react-dom'; 

class Parent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {name: "Frarthur"};
  }
  render() {
    return <div></div>;
  }  
};