12 JAN 2020

react css lifecycle ajax

react.png

CSS react

CSS Stylesheet:

csss2.PNG

csss1

Inline styling:

csss3.PNG

… full article

Component Lifecycle

lc.jpg

Each component has several “lifecycle methods” that you can use to run code at particular times in the process. Methods prefixed with will are called right before something happens, and methods prefixed with did are called right after something happens

Examples:

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request

componentDidUpdate() is invoked immediately after updating occurs. This method is not called for the initial render.

Use this as an opportunity to operate on the DOM when the component has been updated. This is also a good place to do network requests as long as you compare the current props to previous props (e.g. a network request may not be necessary if the props have not changed).

… full article

Ajax

You can use any AJAX library you like with React. Some popular ones are AxiosjQuery AJAX, and the browser built-in window.fetch.

You should populate data with AJAX calls in the componentDidMount lifecycle method. This is so you can use setState to update your component when the data is retrieved.

… full article

More topics covered:

  • Modify css each second
  • lifecycle – loops
  • fetch vs axios
  • ajax result to setState

Links:

 

Leave a comment

Design a site like this with WordPress.com
Get started