Skip to content

Instantly share code, notes, and snippets.

View wgao19's full-sized avatar
👩‍🌾
👩🏻‍🌾

Wei Gao wgao19

👩‍🌾
👩🏻‍🌾
View GitHub Profile
@swyxio
swyxio / createCtx-noNullCheck.tsx
Last active May 4, 2023 02:15
better createContext APIs with setters, and no default values, in Typescript. this is documented in https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/master/README.md#context
// create context with no upfront defaultValue
// without having to do undefined check all the time
function createCtx<A>() {
const ctx = React.createContext<A | undefined>(undefined)
function useCtx() {
const c = React.useContext(ctx)
if (!c) throw new Error("useCtx must be inside a Provider with a value")
return c
}
return [useCtx, ctx.Provider] as const
@taejs
taejs / studying.md
Last active February 27, 2019 07:32
Day 2: Specs Reading: CSS Snapshot 2018 (Overview)

Questions

What is CSS?

Cascading Style Sheet!

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

What is CSS Snapshot?

The document that represents the state of CSS as of each year.

What are the three levels of stability a CSS document has to pass through? What happens during each of those phases?

@tanhauhau
tanhauhau / .zshrc
Created January 16, 2019 07:12
My zsh theme
# theme customisation
PURE_PROMPT_SYMBOL="🦄"
PURE_CMD_MAX_EXEC_TIME=-1
# lambda-pure theme ftw!
ZSH_THEME="lambda-pure"
@heygrady
heygrady / mapDispatchToProps.md
Last active September 16, 2023 19:19
Redux containers: mapDispatchToProps

Redux containers: mapDispatchToProps

This document details some tips and tricks for creating redux containers. Specifically, this document is looking at the mapDispatchToProps argument of the connect function from [react-redux][react-redux]. There are many ways to write the same thing in redux. This gist covers the various forms that mapDispatchToProps can take.

@markerikson
markerikson / dev-blog-post-plans.md
Last active September 9, 2018 13:24
Mark's Dev Blog - tentative future post plans

Jotting down a list of posts I'd like to write. Probably won't write them in this exact order.

  • Practical Redux series
    • Connected lists, basic form editing
    • Form change handling, feature reducers
    • "editing/draft slice" approach
    • Modal management and "picker" modals
    • Handling more complex nested/relational data
    • Entity creation
  • Treeview
@gaearon
gaearon / connect.js
Last active April 11, 2024 06:46
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
import {action1, action2} from "myActions";
import {bindActionCreators} from "redux";
const mapDispatchToProps(dispatch) => {
return {
manuallyBoundAction : (...args) => dispatch(action1(...args)),
autoBoundAction : bindActionCreators(action2, dispatch),
multipleActionsTogether : bindActionCreators({action1, action2}, dispatch)
}
};
@gaearon
gaearon / slim-redux.js
Last active April 25, 2024 18:19
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a