mirror of
https://github.com/aleleba/create-react-ssr.git
synced 2025-06-20 04:48:30 -06:00
PR-753737: Se agregaj Redux al proyecto y al SSR.
This commit is contained in:
@ -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) {
|
||||
|
9
src/frontend/reducers/index.js
Normal file
9
src/frontend/reducers/index.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import testReducer from './testReducer';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
//Here comes the reducers
|
||||
testReducer
|
||||
})
|
||||
|
||||
export default rootReducer
|
3
src/frontend/reducers/initialState.js
Normal file
3
src/frontend/reducers/initialState.js
Normal file
@ -0,0 +1,3 @@
|
||||
let initialState = {}
|
||||
|
||||
export default initialState
|
18
src/frontend/reducers/testReducer.js
Normal file
18
src/frontend/reducers/testReducer.js
Normal 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
|
Reference in New Issue
Block a user