Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react 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 stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #state
ADD COMMENT
Topic
Name
6+1 =