First, an exercise. Can we represent all of css with plain data? Let's try.
let redText = { color: 'red' };
function logger(strings,...values) { | |
var str = ""; | |
for (let i = 0; i < strings.length; i++) { | |
if (i > 0) { | |
if (values[i-1] && typeof values[i-1] == "object") { | |
if (values[i-1] instanceof Error) { | |
if (values[i-1].stack) { | |
str += values[i-1].stack; | |
continue; | |
} |
Feel free to run via...
npx https://gist.github.com/elijahmanor/4cc8e3eac9fb5999c5d759388ff27c64
React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".
With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.
/** | |
* In our app, we have a few middleware that generate a string of HTML. | |
* On occassion it's fine to just use dangerouslySetInnerHTML directly for | |
* those, but that requires that you have a host node for the innerHTML. | |
* | |
* In certain scenarios (like tags in <head />), there's HTML that we need | |
* to insert directly where it is. This component enables that because | |
* we replace <raw-text> and </raw-text> with empty strings. Effectively | |
* making whatever's between <raw-text> and </raw-text> inlined in place. | |
* |
import React from "react"; | |
import useMutableReducer from "./useMutableReducer"; | |
const reducer = (draft, action, state) => { | |
switch (action) { | |
case "increment": | |
draft.count++; | |
break; | |
case "decrement": | |
draft.count--; |
// control props | |
import React from 'react' | |
import _ from 'lodash' | |
import {Switch} from '../switch' | |
const callAll = (...fns) => (...args) => fns.forEach(fn => fn && fn(...args)) | |
const noop = () => {} | |
function toggleReducer(state, {type, initialState}) { |
// src/count-context.js | |
import React from 'react' | |
function countReducer(count, action) { | |
const {step = 1} = action | |
switch (action.type) { | |
case 'INCREMENT': { | |
return count + step | |
} | |
default: { |
import { useState, useEffect, useCallback } from 'react' | |
function usePromise(createPromise) { | |
const [error, setError] = useState() | |
const [value, setValue] = useState() | |
useEffect(() => { | |
let current = true | |
createPromise().then( |