Skip to content

Instantly share code, notes, and snippets.

View luismartinezs's full-sized avatar
😄
Always learning

Luis Martinez Suarez luismartinezs

😄
Always learning
View GitHub Profile
@luismartinezs
luismartinezs / fieldset.html
Last active September 4, 2022 14:49
Fieldset and legend #a11y #html
<!-- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset -->
<form>
<fieldset>
<legend>Choose your favorite monster</legend>
<input type="radio" id="kraken" name="monster" />
<label for="kraken">Kraken</label><br />
<input type="radio" id="sasquatch" name="monster" />
@luismartinezs
luismartinezs / inputs.html
Last active September 4, 2022 14:48
Inputs with suggestions #a11y
<!-- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist -->
<label for="myBrowser">Choose a browser from this list:</label>
<input list="browsers" id="myBrowser" name="myBrowser" />
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
@luismartinezs
luismartinezs / table.html
Last active September 4, 2022 14:44
A11y table #a11y
<!-- Use <caption> -->
<!-- Use scopes (enough for most cases) or ids and headers -->
<!-- Example with scopes -->
<table>
<caption>
Color names and values
</caption>
<tbody>
@luismartinezs
luismartinezs / Emoji.tsx
Last active September 1, 2022 07:46
React a11y emoji #react #a11y
// https://medium.com/@seanmcp/%EF%B8%8F-how-to-use-emojis-in-react-d23bbf608bf7
import React from 'react';
const Emoji = props => (
<span
className="emoji"
role="img"
aria-label={props.label ? props.label : ""}
aria-hidden={props.label ? "false" : "true"}
>
@luismartinezs
luismartinezs / A11yReact.tsx
Last active August 30, 2022 10:39
A11y React components #a11y #react
// https://reactjs.org/docs/accessibility.html
import React from 'react';
function ListItem({ item }) {
return (
// https://reactjs.org/docs/fragments.html
<>
<dt>{item.term}</dt>
<dd>{item.description}</dd>
</>
@luismartinezs
luismartinezs / UseImperativeTimeout.tsx
Last active August 30, 2022 10:01
React useImperativeTimeout #react #hooks
// https://blog.thoughtspile.tech/2021/10/13/really-declarative/
import React, { useRef, useEffect, useCallback, useState } from 'react';
function useImperativeTimeout(callback, delay) {
const timeoutId = useRef(null);
const savedCallback = useRef();
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback;
@luismartinezs
luismartinezs / UseInterval.tsx
Last active August 30, 2022 08:58
react useInterval #react #hooks
// https://overreacted.io/making-setinterval-declarative-with-react-hooks/
import React, { useState, useEffect, useRef } from "react";
import ReactDOM from "react-dom";
function Counter() {
const [count, setCount] = useState(0);
const [delay, setDelay] = useState(1000);
useInterval(() => {
// Your custom logic here
@luismartinezs
luismartinezs / useStableCallback.tsx
Last active August 30, 2022 05:56
React useStableCallback #react #hooks
// https://blog.thoughtspile.tech/2021/04/07/better-usecallback/
const useStableCallback = (callback) => {
const onChangeInner = useRef(callback);
// Added useLayoutEffect here, to work with concurrency
// Because of this, it can't be used during render, only after render
useLayoutEffect(() => {
onChangeInner.current = callback;
});
const stable = useCallback((...args) => onChangeInner.current(...args), []);
@luismartinezs
luismartinezs / WidthWrapper.props.ts
Last active August 2, 2022 10:52
React Width Wrapper #react
export interface IWidthWrapperProps {
children: React.ReactNode;
className?: string;
width?: "text" | "block";
}
@luismartinezs
luismartinezs / App.tsx
Last active July 30, 2022 06:43
Redux toolkit slice #redux-toolkit
import React from "react";
import { Provider } from "react-redux";
import { store } from "./store";
function App() {
return (
<React.StrictMode>
<Provider store={store}>{/* App content */}</Provider>