Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react this.state

import React, { Component } from "react";

class Counter extends Component {
	// you can either initialize state inside constructor
  	constructor() {
		super();
		this.state = {
			count: 1,
			tags: ["tag1", "tag2", "tag3"],
		};
	}
  	// or initialize the state as class field declaration
  	state = {
		count: 1,
		tags: ["tag1", "tag2", "tag3"],
	};
}
Source by reactjs.org #
 
PREVIOUS NEXT
Tagged: #react
ADD COMMENT
Topic
Name
6+2 =