Skip to content

Instantly share code, notes, and snippets.

View mfaridzia's full-sized avatar
📒
storyteller

Muhammad Farid Zia mfaridzia

📒
storyteller
View GitHub Profile
/**
* A quick way of using Markdown inside JSX: via tagged templates
*
* Downsides:
* – Works completely dynamically (no static compilation)
* – Big downside: You must escape backticks.
* Potential work-around in template tag function: result.replace(/∆/ug, '`')
*
* Upsides:
* – Preserves line breaks (JSX doesn’t)
@Mayankgupta688
Mayankgupta688 / react_useMemoryImplementation.jsx
Last active September 28, 2019 17:23
react_useMemoImplementation.jsx
import React, { useState, useMemo } from "react";
export default function SimpleStateHooks() {
const [count, setCount] = useState(1000);
function returnValue(inputValue) {
return inputValue + 10;
}
var calculatedValue = useMemo(() => returnValue(10), [10]);
import * as React from "react";
import { render } from "react-dom";
import produce from "immer";
import { set, has } from "lodash";
import "./styles.css";
function enhancedReducer(state, updateArg) {
// check if the type of update argument is a callback function
if (updateArg.constructor === Function) {
@carpben
carpben / useFocus.ts
Created August 10, 2019 04:52
useFocus.ts
export const useFocus = () => {
const htmlElRef = useRef<HTMLElement>()
const setFocus = () => {
const currentEl = htmlElRef.current
currentEl && currentEl.focus()
}
return [setFocus, htmlElRef] as const
}
@bradtraversy
bradtraversy / eslint_prettier_airbnb.md
Created July 19, 2019 17:54
ESLint, Prettier & Airbnb Setup

VSCode - ESLint, Prettier & Airbnb Setup

1. Install ESLint & Prettier extensions for VSCode

Optional - Set format on save and any global prettier options

2. Install Packages

npm i -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-node eslint-config-node
@mjackson
mjackson / useStorage.js
Last active November 4, 2021 06:36
A React hook for persisting state between page refreshes (also SSR compatible)
import { useEffect, useRef } from 'react';
function getItem(storage, key) {
const value = storage.getItem(key);
if (!value) return null;
try {
return JSON.parse(value);
} catch (error) {
@dsalahutdinov
dsalahutdinov / Dockerfile.dev
Last active May 25, 2021 21:02
Dockerize Ruby backend of the multi-service application for local development
FROM ruby:2.6.1
ARG PG_VERSION
ARG NODE_VERSION
ARG TINI_VERSION=v0.18.0
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_VERSION > /etc/apt/sources.list.d/pgdg.list \
&& curl -o /tmp/nodejs.deb https://deb.nodesource.com/node_11.x/pool/main/n/nodejs/nodejs_$NODE_VERSION-1nodesource1_amd64.deb \
&& apt-get update -qq \
@swyxio
swyxio / final submission.md
Last active April 22, 2023 19:17
Why React is Not Reactive - React Rally CFP

This is the CFP for my React Rally talk, which was eventually accepted and given here: https://www.youtube.com/watch?v=nyFHR0dDZo0.

If you are a first time speaker, my CFP advice for new speakers is here.

Final Submission: Why React is not Reactive

Functional-reactive libraries like RxJS make it easy to understand how data changes, giving us tools to declaratively handle events and manage state. But while our render methods react to state changes, React isn’t reactive. Instead, we write imperative event-handlers, and trip up on gotchas like async setState and race conditions. Why? In this talk we build a Reactive React to show the difference between the "push" and "pull" paradigms of data flow and understand why React chooses to manage Scheduling as a core Design Principle, enabling awesome features like async rendering and Suspense!

Theme: This talk is a deep dive into React's core design principle around scheduling. Instead of abstr