Skip to content

Instantly share code, notes, and snippets.

View alexmochu's full-sized avatar
🤙
Good Vibes Only!

Karanja Mochu alexmochu

🤙
Good Vibes Only!
View GitHub Profile
import { combineReducers } from '@reduxjs/toolkit'
import clicksReducer from './counter'
const clicks = { count: clicksReducer }
export let rootReducer = combineReducers({
...clicks
})
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
import createSagaMiddleware from 'redux-saga';
import { createInjectorsEnhancer } from 'redux-injectors';
import createReducer from './rootReducer'
import rootSaga from './sagas'
export default function configureAppStore(initialState = {}) {
const reduxSagaMonitorOptions = {};
const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions);
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
type CurrentDisplayState = {
clicks: number
}
let initialState: CurrentDisplayState = {
clicks: 0,
}
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
@alexmochu
alexmochu / template.json
Created June 30, 2020 11:30
Contents of Template
{
"package": {
"dependencies": {
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-saga": "^1.1.3"
},
"scripts": {
"serve": "serve -s build",
@alexmochu
alexmochu / App.css
Created June 30, 2020 11:29
Update CSS
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
color: rgb(112, 76, 182);
}
@alexmochu
alexmochu / App.js
Created June 30, 2020 11:28
Setup App.js
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import logo from './logo.svg';
import increment, { incrementAsync, decrement } from './actions';
import Counter from './Counter';
import './App.css';
function App() {
const dispatch = useDispatch();
const counter = useSelector(state => state.count)
@alexmochu
alexmochu / index.js
Last active June 30, 2020 11:27
Bind with React Redux
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import './index.css';
import configureStore from './store'
import App from './App';
import * as serviceWorker from './serviceWorker';
const store = configureStore();
@alexmochu
alexmochu / counter.js
Created June 30, 2020 11:24
Counter Component
import React from 'react';
import './App.css';
const Counter = ({ value, onIncrement, onDecrement, onIncrementAsync }) =>
<div>
<button onClick={onIncrementAsync} className="button">
Increment after 1 second
</button>
{' '}
<button onClick={onIncrement} className="button">
@alexmochu
alexmochu / sagas.js
Created June 30, 2020 11:20
Create Sagas
import { all, call, delay, put, takeEvery } from 'redux-saga/effects'
export function* incrementAsync() {
yield delay(1000)
yield put({type: 'INCREMENT'})
}
export function* watchIncrementAsync() {
yield takeEvery('INCREMENT_ASYNC', incrementAsync)
}