Skip to content

Instantly share code, notes, and snippets.

View jinook929's full-sized avatar

Jinook Jung jinook929

View GitHub Profile
@jinook929
jinook929 / Reset.js
Created May 31, 2021 03:05
React with Hooks, with Redux & React-Redux: Reset.js
import React from 'react'
import '../App.css'
import {resetCount} from '../actions'
import {useDispatch} from 'react-redux'
const Reset = () => {
const dispatch = useDispatch()
return (
<div className="Reset">
@jinook929
jinook929 / Controllers.js
Created May 31, 2021 02:55
React with Hooks, with Redux & React-Redux: Controllers.js
import React from 'react'
import '../App.css'
import {increaseCount, decreaseCount} from '../actions'
import {useSelector, useDispatch} from 'react-redux'
const Controllers = () => {
const count = useSelector(state => state.count)
const dispatch = useDispatch()
return (
@jinook929
jinook929 / Counter.js
Created May 31, 2021 02:53
React with Hooks, with Redux & React-Redux: Counter.js
import React from 'react'
import Controllers from "./Controllers"
import {useSelector} from 'react-redux'
const Counter = () => {
const count = useSelector(state => state.count)
return (
<div className="Counter">
<h1>{count}</h1>
@jinook929
jinook929 / ClickedTime.js
Created May 31, 2021 02:43
React with Hooks, with Redux & React-Redux: ClickedTime.js
import React, {useEffect} from 'react'
import '../App.css'
import {useSelector} from 'react-redux'
const ClickedTime = () => {
const count = useSelector(state => state.count)
const lastChange = new Date().toLocaleString()
useEffect(() => {
const randomHex = '#'+ Math.floor(Math.random()*16777215).toString(16)
@jinook929
jinook929 / ClickedTime.js
Last active May 31, 2021 02:12
React with Hooks, with Redux: ClickedTime.js
...
import {connect} from 'react-redux'
const ClickedTime = (props) => {
...
useEffect(() => {
const randomHex = '#'+ Math.floor(Math.random()*16777215).toString(16)
document.querySelector(".ClickedTime").style.color = randomHex
}, [props.count])
...
@jinook929
jinook929 / ClickedTime.js
Created May 31, 2021 02:10
React with Hooks, with Redux: ClickedTime.js
...
import {connect} from 'react-redux'
const ClickedTime = (props) => {
...
useEffect(() => {
const randomHex = '#'+ Math.floor(Math.random()*16777215).toString(16)
document.querySelector(".ClickedTime").style.color = randomHex
}, [props.count])
...
@jinook929
jinook929 / Reset.js
Created May 31, 2021 01:48
React with Hooks, with Redux: Reset.js
...
import {connect} from 'react-redux'
import {resetCount} from '../actions'
const Reset = (props) => {
return (
<div className="Reset">
<button
id="resetBtn"
onClick={props.resetCount}
@jinook929
jinook929 / index.js
Created May 31, 2021 01:43
React with Hooks, with Redux: reducer/index.js
const countReducer = (state = {count: 0}, action) => {
switch(action.type) {
case "INCREASE_COUNT":
return {...state, count: action.payload}
case "DECREASE_COUNT":
return {...state, count: action.payload}
case "RESET_COUNT":
return {...state, count: action.payload}
default:
@jinook929
jinook929 / Controllers.js, index.js
Last active May 31, 2021 01:18
React with Hooks, with Redux: Controllers.js
// Controllers.js
...
import {connect} from 'react-redux'
import {increaseCount, decreaseCount} from '../actions'
const Controllers = (props) => {
const handleBtnClick = (e) => {
props[e.target.name](props.count)
}
return (
@jinook929
jinook929 / Counter.js
Created May 30, 2021 21:13
React with Hooks, with Redux: Counter.js
...
import {connect} from 'react-redux'
const Counter = (props) => {
return (
<div className="Counter">
<h1>{props.count}</h1>
<Controllers />
</div>
)