Skip to content

Instantly share code, notes, and snippets.

View sayjeyhi's full-sized avatar
:electron:
Building things

Jafar Rezaei sayjeyhi

:electron:
Building things
View GitHub Profile
@iansu
iansu / README.md
Last active March 1, 2021 08:40
Create React App 4.0 Alpha Testing

Create New App

JavaScript Template

npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app

TypeScript Template

npx create-react-app@next --scripts-version=@next --template=typescript@next my-ts-app

@slikts
slikts / react-memo-children.md
Last active May 17, 2024 16:39
Why using the `children` prop makes `React.memo()` not work

nelabs.dev

Why using the children prop makes React.memo() not work

I've recently ran into a pitfall of [React.memo()][memo] that seems generally overlooked; skimming over the top results in Google just finds it mentioned in passing in a [React issue][regit], but not in the [FAQ] or API [overview][react-api], and not in the articles that set out to explain React.memo() (at least the ones I looked at). The issue is specifically that nesting children defeats memoization, unless the children are just plain text. To give a simplified code example:

const Memoized = React.memo(({ children }) => (<div>{children}</div>));
// Won't ever re-render
<Memoized>bar</Memoized>
// Will re-render every time; the memoization does nothing
kill -9 $(lsof -i:PORT -t) 2> /dev/null
@sayjeyhi
sayjeyhi / RaceSaga.js
Last active November 4, 2019 13:51
Advancerd Saga samples
import { race, cancel, take, fork, all, put, select } from 'redux-saga/effects';
export function* fetchDataForPage() {
const userId = yield select(getUserId);
try {
if (!userId) {
throw new Error('No user - aborting');
}
@gaearon
gaearon / uselayouteffect-ssr.md
Last active May 16, 2024 14:13
useLayoutEffect and server rendering

If you use server rendering, keep in mind that neither useLayoutEffect nor useEffect can run until the JavaScript is downloaded.

You might see a warning if you try to useLayoutEffect on the server. Here's two common ways to fix it.

Option 1: Convert to useEffect

If this effect isn't important for first render (i.e. if the UI still looks valid before it runs), then useEffect instead.

function MyComponent() {
@MoienTajik
MoienTajik / iranian-phone-numbers-regex.md
Last active May 20, 2024 10:12
Regex For Iranian Mobile Phone Numbers

Regex For Iranian Phone Numbers

This regex supports all kinds of Iranian mobile phone numbers :

^(\+98|0)?9\d{9}$


Regex Visualized

@edysegura
edysegura / array-reduce.js
Created June 9, 2016 12:53
[JS] Using reduce to calculate average
var scores = [1, 4, 6, 8];
var result = scores.reduce((total, score) => total + score) / scores.length;
console.log(result); // 4.75
@zhiguangwang
zhiguangwang / README.md
Last active April 29, 2024 12:56
Installing and running shadowsocks on Ubuntu Server

Installing and running shadowsocks on Ubuntu Server

16.10 yakkety and above

  1. Install the the shadowsocks-libev package from apt repository.

     sudo apt update
     sudo apt install shadowsocks-libev
    
  2. Save ss.json as /etc/shadowsocks-libev/config.json.

@acauamontiel
acauamontiel / mixins.styl
Last active May 5, 2018 12:28
Useful mixins for Stylus
/*
* Clearfix
*/
clearfix()
&:before,
&:after
content ' '
display table
&:after