Skip to content

Instantly share code, notes, and snippets.

⚛️
useEffect(() => { setWorking(true) })

Konstantin Dichev kdichev

⚛️
useEffect(() => { setWorking(true) })
Block or report user

Report or block kdichev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View test.js
// bad
<div
className={`miniBook__tab miniBook__tabOneWay${oneWay ? ' miniBook__tab--active' : ''}`}
onClick={() => this.tabOnClick(oneWay)}
>
{children}
</div>
// better
<div
View data.js
// that needs to become something readable for a pathfinding algorithm like
// [
// [0, 0, 0, 1, 0],
// [1, 0, 0, 0, 1],
// [0, 0, 1, 0, 0],
// ]
const apiData = [
[
"west",
View grid.js
// data contains width * height walkable path entries
// each entry has at most two walls "west" | "north"
// to find all walkable directions from X use the array entries X, X+1 and X+width to construct walls
// grid is 15x15 blocks
const data = [["west","north"],["north"],["west","north"],["north"],["north"],["west","north"],["north"],["north"],["west","north"],["north"],["north"],["north"],["west","north"],["north"],["north"],["west","north"],["west"],["west"],["north"],["west"],["west"],["west"],["west"],["north"],["north"],[],["west"],["north"],["north"],[],["west"],[],["west"],["west"],["north"],[],["west"],["north"],["north"],["west","north"],["north"],[],["west","north"],["north"],["west"],["west"],["north"],["north"],["west"],["north"],["north"],["north"],["north"],["west"],["north"],["north"],["north"],["west"],["west"],["west"],["west","north"],["north"],["west"],["west"],["west","north"],["north"],["north"],["west"],["west","north"],["north"],["west"],["west"],[],["west"],["north"],["west"],["west
View gist:07529da3743d1646bedb2c3562633635
const data = [
[
'west',
'north'
],
[
'north'
],
[
'north'
View endpoints.graphql
mutation {
createCar(
name: "car"
carBrand: "Mercedes-Benz"
carMode: "C63 AMG"
carYear: "2018-06-19T19:51:13.701Z"
) {
id
carBrand
}
View gist:3d57c8c3f21751d23f10f83b86361beb
const asyncAction = (dataMaybe) => async (dispatch, getState) => {
// u can dispatch all kinds of actions here according to outcome
dispatch({type: "FETCHING_START"}
// if u need to use store data but can be passed as arg from react component when invoking
const store = getState().theReducer
const response = await myFetchFunction()
if (response) {
dispatch({type: "FETCHING_SUCCESS", payload: {response}}
View gist:0d1fade1f2e5cce048b1142d2cedde92
import { connect } from "react-redux";
const mapStateToProps = ({
theReducer: { city, humidity, temperature, wind }
}) => ({
city,
humidity,
temperature,
wind
});
@kdichev
kdichev / js
Created Apr 8, 2018
reducers.js
View js
import { combineReducers } from "redux";
const initialState = {
hi: "hi"
};
export const theReducer = (state = initialState, action) => {
switch (action.type) {
case "SOMETHING_HAPPENING":
return { ...state, hi: "bye" };
View store.js
import { createStore, applyMiddleware, compose } from "redux";
import thunkMiddleware from "redux-thunk";
const configureStore = (initialState) =>
createStore(
// here reducers
// REDUCERS.js
persistedState,
compose(
applyMiddleware(
View index.js
import React from 'react'
// simple stateless component (children is reserved word)
const DisplayHelloWorld = (props) => (
<div>
message: {props.children}
name: {props.name}
</div>
)
You can’t perform that action at this time.