score:2
Accepted answer
class App extends React.Component {
constructor(props) {
super(props);
// Initialise your state here.
this.state = {
tabList: tabList,
currentTab: 1
};
// Bind your functions to this, avoiding scoping issues.
this.changeTab = this.changeTab.bind(this);
}
// Use function property syntax
changeTab(tab) {
this.setState({
currentTab: tab.id
});
}
render() {
// deconstruct your state.
const { currentTab, tabList } = this.state;
return(
<div>
<Tabs currentTab={currentTab} tabList={tabList} changeTab={this.changeTab}/>
<Content currentTab={currentTab} />
</div>
);
}
}
score:3
constructor(props) {
super(props);
this.state = {
tabList: tabList,
currentTab: 1
};
}
Source: stackoverflow.com
Related Query
- Writing "getInitialState" using ES6 standards
- How to deploy Node.js / React application to Heroku using Babel when writing ES6 code?
- What is the difference between using constructor vs getInitialState in React / React Native?
- What's the difference between "super()" and "super(props)" in React when using es6 classes?
- Pros/cons of using redux-saga with ES6 generators vs redux-thunk with ES2017 async/await
- How to import and export components using React + ES6 + webpack?
- React, ES6 - getInitialState was defined on a plain JavaScript class
- React passing parameter via onclick event using ES6 syntax
- how to create common helper class in React JS using ES6 which is used by another component?
- componentDidMount method not triggered when using inherited ES6 react class
- Change object key using Object.keys ES6
- How to set initial state with using ES6 class in React?
- fetch method is not defined using ES6 fetch in React
- Using ES6 Map with React and/or Redux
- Is a good convention using semicolon at the end of the line when using ES6 in babel
- create timer with react native using es6
- React getInitialState using props
- Using Jquery and Bootstrap with Es6 Import for React App
- Using ES6 Classes with Redux
- How to import Firebase Firestore into a create-react-app project using ES6 syntax
- Converting jsx with ES6 import syntax using reactify
- Using create react app, and having ES6 dependencies
- How to transpile React ES6 classes using Grunt + Browserify + Reactify?
- Is there a method to reset a react component using ES6 classes to its initial state?
- Using express and es6 to render react and jsx server side
- Does the use of es6 named imports reduce the bundle size when using webpack
- How could I know I am using ES6 in React?
- How to use jest with node_modules using es6 within NX project
- Writing to files using File System Access API fails in Electron + Create React App
- Using module.exports in React ES6
More Query from same tag
- React Navigation, How do I test a the path of a Navlink?
- how to sort Immutable data
- react handle simultaneous click and blur events
- React-router is not displaying anything in the browser
- Prevent remounting of expensive (class) component with shouldComponentUpdate() (List of images, inside router)
- useState to update an instance variable of many variables inside an object
- 'withRouter' is not exported from 'react-router-dom'
- How to add custom request header to testcafe test suite?
- why is react returning parsing error: unexpected token
- multiline with <ListItemText>
- How to send values from api after maping react hooks
- toContainHTML providing an error when HTML element exists (React Testing)
- How can i find the length of a nested array objectlist in react?
- Can useReducer do a functional update similar to useState?
- React Router with redirection to login page but also to have 404 NotFound route
- How to set backEnd URL in frontEnd react
- How to define container size for react-testing-library?
- How to make fullscreen picture in a meteor/react setup?
- Rounding issue using toFixed()
- Best way to pass images in static react app
- Test react services using jest
- React with Firebase - splitting authorisation between CRUD actions
- React.js - audio.duration returns NaN & How to upload blobUrl to amazon s3
- react tabs call componentDidMount every time when switching tab
- map redux state to prop in authenticated react route component
- Make a new div element for each element in an array with JSX?
- main.js 404 error for MIT react-starter-kit
- How can I re-trigger a custom hook inside my react component, when its states have not changed?
- Read properties of a script which is returned when my page is loaded
- Save values in array of data