Skip to content

Instantly share code, notes, and snippets.

View ConAntonakos's full-sized avatar
🏠
Working from home

Constantine Antonakos ConAntonakos

🏠
Working from home
View GitHub Profile
import { useState, useEffect, useCallback } from 'react'
function usePromise(createPromise) {
const [error, setError] = useState()
const [value, setValue] = useState()
useEffect(() => {
let current = true
createPromise().then(
let UserContext = React.createContext();
class App extends React.Component {
state = {
user: null,
setUser: user => {
this.setState({ user });
}
};

suspense-loader

Installation (sorry)

npm i THIS_URL

Usage

@gaearon
gaearon / prepack-gentle-intro-1.md
Last active February 13, 2024 14:30
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@etienne-dldc
etienne-dldc / combineContext.js
Created March 28, 2018 18:38
A small function to combine react Contexts.
import React from 'react';
function onlyChild(children) {
return Array.isArray(children) ? children[0] : children;
}
export function combineContext(contexts) {
class Provider extends React.Component {
render() {
const init = this.props.children;
@threepointone
threepointone / 0 basics.md
Last active March 21, 2023 01:53
css-in-js

A series of posts on css-in-js

0. styles as objects

First, an exercise. Can we represent all of css with plain data? Let's try.

let redText = { color: 'red' };

3 Gripes With React

I started using React 3.5 years ago, and I still love it. It was such a well-designed solution that not much has changed since then, only superficial stuff like naming. What I learned then is still wholly applicable today because it's such a good idea (although now you can choose from many other libraries). On top of that, we now benefit from an entirely new architecture (fiber) without changing much.

@nitin42
nitin42 / require.js
Created October 8, 2017 15:33
How Node.js's require() works ??
const some_module = require('some_module')
/**
* require('some_module') calls Module._load
*
* Module._load then tries to load the module with a filename (also save it to the cache) using module.load(filename)
*
* module.load(filename), given a filename, passes it to the proper extension handler ('.js', '.json')
*
* If there were any errors when loading the file, it deletes the file from the cache (delete Module._cache[filename]) and throws an error