Skip to content

Instantly share code, notes, and snippets.

export const loadPost = async ({ state, effects }, id) => {
state.loading = true;
const { post } = await effects.gql.queries.post({ id });
state.post = post;
state.loading = false;
}
export const myAction = ({ state, effects, actions }, value) => {
}
@jide
jide / index.html
Last active January 12, 2020 20:58
context state
<div id="root"></div>
‎‎​
@jide
jide / UsersContainer.js
Last active December 19, 2017 02:31
More complex optimized redux connectors.
import { connect } from 'react-redux';
import { removeUser } from '../reducers/user';
import Users from '../components/Users';
const Container = connect(
(state, props) => ({
users: state.users.all,
options: state.options,
isAdmin: state.currentUser[props.userId].isAdmin === true
@jide
jide / AddTodoContainer.js
Last active December 19, 2017 02:30
Optimized redux connectors.
import { connect } from 'react-redux';
import { addTodo } from '../reducers/todo';
import AddTodo from '../components/AddTodo';
const Container = connect(
state => ({
todos: state.todos.all
}),
{ addTodo },
@jide
jide / AddTodoContainer.js
Last active November 24, 2017 23:26
Unoptimized redux connectors.
import { connect } from 'react-redux';
import { addTodo } from '../reducers/todo';
import AddTodo from '../components/AddTodo';
const Container = connect(
state => ({
todos: state.todos.all
}),
{ addTodo }
@jide
jide / *tracked.md
Last active March 30, 2017 23:24 — forked from developit/*tracked.md

tracked (fork) npm

@tracked is a decorator for Preact that makes working with state values no different than properties on your component instance.

It's one 300 byte function that creates a getter/setter alias into state/setState() for a given key, with an optional initial value. The "magic" here is simply that it works as a property decorator rather than a function, so it appears to integrate directly into the language.

tracked has no dependencies and works with any component implementation that uses this.state and this.setState().

Installation

@jide
jide / block.jsx
Last active March 17, 2017 00:22
const Block = ({ x, width, title, subtitle }) =>
<div style={{ left: x, width }}>
<div style={{ color: width > 100 ? 'red' : 'green' }}>{ title }</div>
<div>{ subtitle }</div>
</div>
import React, { Component } from 'react';
import styled from 'styled-components';
import { Motion, spring } from 'react-motion';
const Title = styled.h1`
font-size: 3.5em;
text-align: center;
transform: var(--transform);
color: var(--color, palevioletred);
`;