Preact: Router.js:130 Uncaught TypeError: _this.setState is not a function

Created on 27 Jun 2017  路  5Comments  路  Source: preactjs/preact

page work error when use react-router

has fix question

Most helpful comment

hey @AnkitJainAJ, I'm getting the same issue with react-router. Digging into the source code, it seems that react-router uses create-react-class, which will need to be aliased to the preact-compat version with webpack, browserify or babel, e.g:

// webpack.config.js
module.exports = {
// ...
    alias: {
        'react': 'preact-compat',
        'react-dom': 'preact-compat',
        'create-react-class': 'preact-compat/lib/create-react-class'
    }
}

I hope this helps!

All 5 comments

Can you provide more details? Are you using preact-compat to load react-router? What version of the react-router library are you using?

yes , i am using preact-compat .
"preact-compat": "3.16.0",
"react-router": "3.0.5"

Please help.

hey @AnkitJainAJ, I'm getting the same issue with react-router. Digging into the source code, it seems that react-router uses create-react-class, which will need to be aliased to the preact-compat version with webpack, browserify or babel, e.g:

// webpack.config.js
module.exports = {
// ...
    alias: {
        'react': 'preact-compat',
        'react-dom': 'preact-compat',
        'create-react-class': 'preact-compat/lib/create-react-class'
    }
}

I hope this helps!

Hi @e-r-w,
It worked , thanks for the help.

Closing since @e-r-w found the issue - hopefully anyone searching for it finds this one :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulkatich picture paulkatich  路  3Comments

adriaanwm picture adriaanwm  路  3Comments

jasongerbes picture jasongerbes  路  3Comments

jescalan picture jescalan  路  3Comments

kay-is picture kay-is  路  3Comments