Skip to content

Instantly share code, notes, and snippets.

View kentcdodds's full-sized avatar
馃
working hard to make the world better with software

Kent C. Dodds kentcdodds

馃
working hard to make the world better with software
View GitHub Profile
@aweary
aweary / App.js
Last active August 29, 2021 14:06
import React from "react";
import useMutableReducer from "./useMutableReducer";
const reducer = (draft, action, state) => {
switch (action) {
case "increment":
draft.count++;
break;
case "decrement":
draft.count--;
/**
* 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.
*
@bvaughn
bvaughn / index.md
Last active February 25, 2025 15:56
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

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.

@elijahmanor
elijahmanor / README.md
Last active November 8, 2018 19:34
Has Deprecated Packages

Feel free to run via...

npx https://gist.github.com/elijahmanor/4cc8e3eac9fb5999c5d759388ff27c64

@getify
getify / 1.js
Last active March 19, 2023 08:32
tag function for formatting console.log(..) statements
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;
}
@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' };
@kentcdodds
kentcdodds / kent-newsletters.json
Last active April 1, 2018 02:50
Where my stuff has been mentioned in newsletters (AFAIK). I'm planning on building something small with this eventually...
[
{
"link": "https://blog.kentcdodds.com/migrating-to-jest-881f75366e7e",
"title": "Migrating to Jest",
"comment": "Kent C. Dodds is super excited about Jest as an alternative to AVA and Mocha, and explains how he was won over after not initially being a fan.",
"newsletter": {
"name": "JavaScript Weekly",
"issue": 310,
"link": "http://javascriptweekly.com/issues/310"
}
@ceejbot
ceejbot / esm_in_node_proposal.md
Last active June 20, 2024 10:45
npm's proposal for supporting ES modules in node

ESM modules in node: npm edition

The proposal you鈥檙e about to read is not just a proposal. We have a working implementation of almost everything we discussed here. We encourage you to checkout and build our branch: our fork, with the relevant branch selected. Building and using the implementation will give you a better understanding of what using it as a developer is like.

Our implementation ended up differing from the proposal on some minor points. As our last action item before making a PR, we鈥檙e writing documentation on what we did. While I loathe pointing to tests in lieu of documentation, they will be helpful until we complete writing docs: the unit tests.

This repo also contains a bundled version of npm that has a new command, asset. You can read the documentation for and goals of that comma

@kentcdodds
kentcdodds / with-foo.js
Created November 15, 2017 16:18
Which of these is a higher order component?
// Which of these things is the "Higher Order Component?"
function withFoo(Component) { // <-- this is a function, not a component
class Wrapper extends React.Component { // <-- this is a component
static displayName = `withFoo(${Component.displayName || Component.name})`
static propTypes = {innerRef: PropTypes.func}
static WrappedComponent = Component
render() {
const {innerRef, ...remainingProps} = this.props
return <Component {...remainingProps} foo="FOO!" ref={innerRef} />
@kentcdodds
kentcdodds / index.html
Last active June 24, 2021 19:48
The one true react boilerplate
<body>
<div id="鈿涳笍"></div>
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.js"></script>
<script type="text/babel">
ReactDOM.render(<div>Hello World!</div>, document.getElementById('鈿涳笍'))
</script>
</body>