Skip to content

Instantly share code, notes, and snippets.

View penx's full-sized avatar

Alasdair McLeay penx

  • Brighton, UK
  • 02:51 (UTC)
  • X @penx
View GitHub Profile
/**
Example usage of React Router 4 to handle:
- Known routes to render a specific component, e.g. /
- An array of valid top level slugs, e.g. /:pageId
- A dictionary of top level slugs that should redirect, e.g. /:redirectId
- An array of valid slugs for a known subroute, e.g. /items/:itemId
- 404 for anything that is not handled, including invalid slugs, with a correct http response
- Server side example, but ReactApp is written so that routing would work universally
import React, { useState, createContext, useContext } from "react";
const MyContext = createContext();
const Provider = props => {
const [value, set] = useState("initial");
return <MyContext.Provider value={{ value, set }} {...props} />;
};
const Value = () => {
import React, { useState, createContext, useContext } from "react";
const SetContext = createContext();
const ValueContext = createContext();
const Provider = props => {
const [value, set] = useState("initial");
return (
<SetContext.Provider value={set}>
<ValueContext.Provider value={value} {...props} />
import React, { useState, createContext, useContext } from "react";
const SetContext = createContext();
const ValueContext = createContext();
const Provider = props => {
const [value, set] = useState("initial");
return (
<ValueContext.Provider value={value}>
<SetContext.Provider value={set} {...props} />
import React, { useState, createContext, useContext } from "react";
const SetContext = createContext();
const ValueContext = createContext();
const SetProvider = React.memo(({ set, ...props }) => (
<SetContext.Provider value={set} {...props} />
));
const Provider = props => {
@penx
penx / features.md
Last active October 9, 2023 15:47
CSS preprocessors
@penx
penx / index.html
Created December 6, 2023 11:45
Radix themes/chromium issue
<!DOCTYPE html>
<html lang="en">
<head>
<style>
:where(.rt-Inset) > * {
--margin-top-override: initial;
}
.rt-Inset:where(.rt-r-side-all) {