admin管理员组

文章数量:1303530

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 "./ponents/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?

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 "./ponents/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?

Share asked Sep 12, 2017 at 21:28 ST80ST80 3,90317 gold badges72 silver badges144 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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

export default class ReleaseState {
  ...

It looks like you might have forgotten to export ReleaseState?

export default releaseState;

本文标签: javascriptReactJS default is not a constructorStack Overflow