Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS .default is not a constructor

I'm new to React and Mobx so I try to do a small app. When I try to run it i get the error: Uncaught TypeError: _releasesState2.default is not a constructor. I'm about to bash my head in since I have no clue what the issue is. Here is what I got so far:

my index.js:

import React from "react";
import ReactDOM from "react-dom";

import Releases from "./components/releases";

class App extends React.Component {
  constructor() {
    super();
  } 
  render() {
    return (
        <div>
           <Releases />
        </div>
     )
  }
}

ReactDOM.render(<App/>, window.document.getElementById("app"));

the releases.js:

import React from "react";
import { observer } from "mobx-react";

import ReleaseState from "./releases-state";

@observer
export default class Releases extends React.Component {
   constructor() {
     super();

    this.state = new ReleaseState();
   }
   render() {
     return (
        <div>
            // content here
        </div>
      ) 
   }
}

and the releases-state.js:

import { observable } from "mobx"

class ReleaseState {
   @observable releases = [];

   constructor() {
      let data = [] // some array with data
   }
}

const releaseState = new ReleaseState();

Can someone maybe tell me whats wrong here?

like image 384
ST80 Avatar asked Sep 12 '17 21:09

ST80


1 Answers

You did not export the ReleaseState class in release-state.js. Try modifying your code to:

export default class ReleaseState {
  ...
like image 67
Tamas Hegedus Avatar answered Nov 07 '22 04:11

Tamas Hegedus