Skip to content

Commit

Permalink
Connect React Components to Redux
Browse files Browse the repository at this point in the history
  • Loading branch information
15Dkatz committed Oct 22, 2022
1 parent 563eef7 commit 13cf539
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion evens-or-odds/src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';

class App extends Component {
render() {
console.log('this', this);

return (
<div>React App</div>
);
}
}

export default App;
const mapStateToProps = state => {
console.log('state', state);

return { gameStarted: state.gameStarted };
}

const componentConnector = connect(mapStateToProps);

export default componentConnector(App);
7 changes: 6 additions & 1 deletion evens-or-odds/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { configureStore } from '@reduxjs/toolkit';
import { Provider } from 'react-redux';
import rootReducer from './reducers';
import App from './components/App';
import './index.css';
Expand All @@ -13,4 +14,8 @@ store.subscribe(() => {
});

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);
root.render(
<Provider store={store}>
<App />
</Provider>
);

0 comments on commit 13cf539

Please sign in to comment.