From 13cf5393393d1c2cf2370415a9a48579216e2a53 Mon Sep 17 00:00:00 2001
From: David Katz <15Dkatz@shcp.edu>
Date: Fri, 21 Oct 2022 17:00:24 -0700
Subject: [PATCH] Connect React Components to Redux
---
evens-or-odds/src/components/App.js | 13 ++++++++++++-
evens-or-odds/src/index.js | 7 ++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/evens-or-odds/src/components/App.js b/evens-or-odds/src/components/App.js
index 4981afb..d6e1e83 100644
--- a/evens-or-odds/src/components/App.js
+++ b/evens-or-odds/src/components/App.js
@@ -1,11 +1,22 @@
import React, { Component } from 'react';
+import { connect } from 'react-redux';
class App extends Component {
render() {
+ console.log('this', this);
+
return (
React App
);
}
}
-export default App;
+const mapStateToProps = state => {
+ console.log('state', state);
+
+ return { gameStarted: state.gameStarted };
+}
+
+const componentConnector = connect(mapStateToProps);
+
+export default componentConnector(App);
diff --git a/evens-or-odds/src/index.js b/evens-or-odds/src/index.js
index 1883f35..af89179 100644
--- a/evens-or-odds/src/index.js
+++ b/evens-or-odds/src/index.js
@@ -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';
@@ -13,4 +14,8 @@ store.subscribe(() => {
});
const root = ReactDOM.createRoot(document.getElementById('root'));
-root.render();
+root.render(
+
+
+
+);