Difference between using constructor vs getInitialState in React / React Native?

var TodoApp = React.createClass({ 
propTypes: {
title: PropTypes.string.isRequired
},
getInitialState () {
return {
items: []
};
}
});
class TodoApp extends React.Component {
constructor () {
super()
this.state = {
items: []
}
}
};

--

--

--

Data Analysis and ML| UI Designer | Python |Tableau |AR |Arduino |React Native

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Laravel — The Basics — Requests (官方文件原子化翻譯)

POSTING to your Express server

Difference between var, let and const in Javascript

Insights to be a UI developer

Angular 12 Multiple Image Upload To S3 using DropZone & AWS-SDK

Rendering child elements in React using Fragments

The New ARKit API for React Native…

What is React.js ?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akash Singh

Akash Singh

Data Analysis and ML| UI Designer | Python |Tableau |AR |Arduino |React Native

More from Medium

How to use useLastCall hook in your react project.

Why You Should Use React for Building Chat App

Request and cache data in React like a pro

This Week In React #92: Remix, MDX 2, Lifetime Analysis, Story of React, Quick Start Docs…