Skip to content

Instantly share code, notes, and snippets.

View francoisgeorgy's full-sized avatar

François Georgy francoisgeorgy

View GitHub Profile
@francoisgeorgy
francoisgeorgy / jquery-es6-example.md
Created March 23, 2020 13:16 — forked from mgol/jquery-es6-example.md
jQuery ES6 modules example usage

jQuery source is now authored using ES6 modules. It's possible to use them directly in the browser without any build process.

To test it locally, first clone the jQuery repository:

git clone [email protected]:jquery/jquery.git

Then, write the following index.html file:

@francoisgeorgy
francoisgeorgy / useStickyState.js
Created March 22, 2020 20:17
#react state in local storage (#hook)
function useStickyState(defaultValue, key) {
const [value, setValue] = React.useState(() => {
const stickyValue = window.localStorage.getItem(key);
return stickyValue !== null
? JSON.parse(stickyValue)
: defaultValue;
});
React.useEffect(() => {
window.localStorage.setItem(key, JSON.stringify(value));
}, [key, value]);
@francoisgeorgy
francoisgeorgy / react-typescript.ts
Last active March 22, 2020 20:14
#react #typescript
// Nullable values to hooks
const [user, setUser] = React.useState<IUser | null>(null);
// Generic Components
interface Props<T> {
items: T[];
renderItem: (item: T) => React.ReactNode;
}
@francoisgeorgy
francoisgeorgy / interface-vs-types.ts
Created March 22, 2020 20:08
#typescript interfaces vs types
//extending interfaces
interface PartialPointX { x: number; }
interface Point extends PartialPointX { y: number; }
//extending types
type PartialPointX = { x: number; };
type Point = PartialPointX & { y: number; };
// Interface extends type
type PartialPointX = { x: number; };
@francoisgeorgy
francoisgeorgy / react-ts-enums.ts
Created March 22, 2020 20:07
#react #typescript enums
enum SelectableButtonTypes {
Important = "important",
Optional = "optional",
Irrelevant = "irrelevant"
interface IButtonProps {
text: string,
/** The type of button, pulled from the Enum SelectableButtonTypes */
type: SelectableButtonTypes,
@francoisgeorgy
francoisgeorgy / react-ts-props.ts
Last active March 22, 2020 20:18
#react #typescript props
interface IButtonProps {
text: string,
type: ButtonTypes,
action: () => void
}
const ExtendedButton : React.FC<IButtonProps> = ({text, type, action}) => {
//...
}
@francoisgeorgy
francoisgeorgy / react-composable-children.jsx
Created March 22, 2020 09:55
#react composable children
function Box({ as = "div", children, ...props }) {
if (typeof children === "function") {
return children(props);
}
return React.createElement(as, props, children);
}
// <div id="id">
<Box id="id" />
@francoisgeorgy
francoisgeorgy / responsive-grid.css
Last active March 22, 2020 09:41
responsive css #grid
.container {
display: grid;
grid-gap: 5px;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-template-rows: repeat(2, 100px);
}
@francoisgeorgy
francoisgeorgy / reverse-map.js
Last active March 22, 2020 09:25
reverse #array in javascript
let a = ["zero", "one", "two", "three"];
a.slice(0).reverse().map((o, i) => {
console.log(`${i}, ${o}`);
});
/* RESULT:
> let a = ["zero", "one", "two", "three"];
> a.slice(0).reverse().map((o, i) => { console.log(`${i}, ${o}`); });
0, three
1, two
@francoisgeorgy
francoisgeorgy / typo.css
Last active March 22, 2020 09:39
how to set typography units #web #ui #css
html {
font-size: 16px;
@media (min-width: 800px) {
font-size: 18px;
}
@media (min-width: 1200px) {
font-size: 20px;
}
}