PR-753737: Se agregaj Redux al proyecto y al SSR.

This commit is contained in:
2022-04-18 03:59:56 +00:00
parent 7e018e2763
commit fdfd3641c1
11 changed files with 107 additions and 8 deletions

View File

@ -4,17 +4,49 @@ import { createRoot } from 'react-dom/client';
import { BrowserRouter as Router } from 'react-router-dom';
//History
import { createBrowserHistory } from 'history';
//Redux
import { createStore } from 'redux'; //, applyMiddleware
import { Provider } from 'react-redux';
import { composeWithDevTools as composeWithDevToolsWeb } from 'redux-devtools-extension';
import { config } from '../config';
import reducer from './reducers';
import initialState from './reducers/initialState';
import App from './components/App';
import './styles/global.sass';
//Redux DevTools
/* declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?: typeof compose;
}
} */
const { env } = config
const composeEnhancers = composeWithDevToolsWeb({
// Specify here name, actionsBlacklist, actionsCreators and other options
});
const store = env === 'development' ? createStore(
reducer,
initialState,
composeEnhancers(),
) : createStore(
reducer,
initialState,
)
const container = document.getElementById('app');
const root = createRoot(container);
const history = createBrowserHistory()
root.render(
<Router history={history}>
<App tab="home" />
</Router>
<Provider store={store}>
<Router history={history}>
<App tab="home" />
</Router>
</Provider>
);
if (module.hot) {

View File

@ -0,0 +1,9 @@
import { combineReducers } from 'redux';
import testReducer from './testReducer';
const rootReducer = combineReducers({
//Here comes the reducers
testReducer
})
export default rootReducer

View File

@ -0,0 +1,3 @@
let initialState = {}
export default initialState

View File

@ -0,0 +1,18 @@
const initialState = {
hello: 'world'
}
let testReducer = (state = initialState, action) => {
switch (action.type){
case 'CHANGE_HELLO': {
let newHello = action.payload.hello
return {
hello: newHello
}
}
default:
return state
}
}
export default testReducer