Skip to content

Instantly share code, notes, and snippets.

@pinne
Created January 9, 2017 19:51
Show Gist options
  • Save pinne/54b74403219d16bc07b504930fe78854 to your computer and use it in GitHub Desktop.
Save pinne/54b74403219d16bc07b504930fe78854 to your computer and use it in GitHub Desktop.
//App.js
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createStore } from 'redux';
class App extends Component {
constructor(props) {
super(props);
}
render() {
const props = this.props;
const { store } = this.context;
const state = store.getState();
return (
<div>
{state.state}
</div>
);
}
}
export default App;
bundle.js:34830Uncaught TypeError: Cannot read property 'getState' of undefined
at App.render (bundle.js:34830)
at bundle.js:26620
at measureLifeCyclePerf (bundle.js:25899)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (bundle.js:26619)
at ReactCompositeComponentWrapper._renderValidatedComponent (bundle.js:26646)
at ReactCompositeComponentWrapper.performInitialMount (bundle.js:26186)
at ReactCompositeComponentWrapper.mountComponent (bundle.js:26082)
at Object.mountComponent (bundle.js:18463)
at ReactCompositeComponentWrapper.performInitialMount (bundle.js:26195)
at ReactCompositeComponentWrapper.mountComponent (bundle.js:26082)
render @ bundle.js:34830
(anonymous) @ bundle.js:26620
measureLifeCyclePerf @ bundle.js:25899
_renderValidatedComponentWithoutOwnerOrContext @ bundle.js:26619
_renderValidatedComponent @ bundle.js:26646
performInitialMount @ bundle.js:26186
mountComponent @ bundle.js:26082
mountComponent @ bundle.js:18463
performInitialMount @ bundle.js:26195
mountComponent @ bundle.js:26082
mountComponent @ bundle.js:18463
performInitialMount @ bundle.js:26195
mountComponent @ bundle.js:26082
mountComponent @ bundle.js:18463
mountComponentIntoNode @ bundle.js:31446
perform @ bundle.js:19484
batchedMountComponentIntoNode @ bundle.js:31468
perform @ bundle.js:19484
batchedUpdates @ bundle.js:28887
batchedUpdates @ bundle.js:18101
_renderNewRootComponent @ bundle.js:31662
_renderSubtreeIntoContainer @ bundle.js:31743
render @ bundle.js:31764
(anonymous) @ bundle.js:10851
__webpack_require__ @ bundle.js:556
fn @ bundle.js:87
(anonymous) @ bundle.js:591
__webpack_require__ @ bundle.js:556
(anonymous) @ bundle.js:579
(anonymous) @ bundle.js:582
bundle.js:796 ./src/App.js
/Users/simon/repo/react-test/src/App.js
3:10 warning 'connect' is defined but never used no-unused-vars
4:10 warning 'createStore' is defined but never used no-unused-vars
7:3 warning Useless constructor no-useless-constructor
12:11 warning 'props' is assigned a value but never used no-unused-vars
✖ 4 problems (0 errors, 4 warnings)
printWarnings @ bundle.js:796
handleWarnings @ bundle.js:809
connection.onmessage @ bundle.js:855
EventTarget.dispatchEvent @ bundle.js:2899
(anonymous) @ bundle.js:6072
SockJS._transportMessage @ bundle.js:6070
EventEmitter.emit @ bundle.js:2834
WebSocketTransport.ws.onmessage @ bundle.js:1189
//index.js
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import App from './App';
import './index.css';
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state + 1;
default:
return state;
}
};
const store = createStore(counter);
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment