theJuls theJuls - 1 year ago 163
React JSX Question

Cannot reac property 'setState' of null react

This code was given to me while answering another question, it works fine in codepen. Original code
However when I try adapting it to my project, first of all the arrow function is not recognized and i get the Unexpected token error at this arrow function:

getBtnId = (e) => {
//code in here

So I changed it into a regular function, and now the component looks like this:

export default class HelpPage extends React.Component {
constructor(props) {
this.state = {
panelIndex: 0

getBtnId (e) {
if( && == "BUTTON") {
panelIndex: Number(
return e;

render() {
return (
<div className="container">


However now whenever I press one of the buttons I get "Uncaught TypeError: Cannot read property 'setState' of null"

What can I do now to fix this?


Answer Source

Actually this.getBtnId.bind(this) do nothing !

This will solve your problem :

this.getBtnId = this.getBtnId.bind(this);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download