Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar

Artem Zakharchenko kettanaito

View GitHub Profile
@kettanaito
kettanaito / App.jsx
Created May 27, 2020 06:33
CSS Variables in Styled Components
import { createGlobalStyle, css } from 'styled-components'
const GlobalStyle = createGlobalStyle`
html {
/* Maps all colors from the `theme` to CSS variables: */
${({ theme }) => Object.entries(theme.colors).map(([name, value]) => css`
--${camelCaseToKebabCase(name)}: ${value};
`)}
}
`
@kettanaito
kettanaito / app.js
Created April 6, 2020 07:05
IE-specific bundle
if (__IE__) {
const ieSpecificShim = require('ie-shim')
ieSpecificShim(...)
}
@kettanaito
kettanaito / gatsby-config.js
Created March 18, 2020 10:36
Gatsby custom field resolver
// Importing this fails, as the plugin is distributed in modern module format
// and `gatsby-config.js` is not transpiled.
const firebase = require('gatsby-plugin-firebase')
exports.createResolvers = ({ createResolvers }) => {
const resolvers = {
Query: {
customField: {
type: 'String',
resolve() {
@kettanaito
kettanaito / usage.jsx
Last active March 16, 2020 18:29
useFetch React hook
import React from 'react'
import { useFetch } from './hooks/useFetch'
const Example = () => {
const { data, loading, error } = useFetch('https://api.github.com/user/octocat')
if (loading) {
return <Spinner />
}
@kettanaito
kettanaito / styles.scss
Created February 5, 2020 13:39
Tooltip tick via pseudo-elements
.tooltip {
position: absolute;
top: 100%;
left: 0;
width: 100%;
max-width: 350px;
padding: 0.5rem 1rem;
background-color: #fff;
border: 1px solid #000;
border-radius: 4px;
@kettanaito
kettanaito / README.md
Created February 3, 2020 11:27
Getting started with Redux

Getting started with Redux

What is Redux?

Redux is a state management library. It implements a Flux pattern of handling the data and its primary feature is the reducing of the previous state to produce the next state.

What is Flux?

Flux is an architecture pattern to handle data fetching. It splits data fetching into separate layers, making them predictable, but also embeds a "model" and "controller" parts of traditional MVC into modern applications.

@kettanaito
kettanaito / code.js
Created January 25, 2020 10:26
Boolean: De Morgan's Laws
!(A && B) // is equivalent to
!A || !B
!(A || B) // is equivalent to
!A && !B
@kettanaito
kettanaito / Canvas.jsx
Created December 22, 2019 13:48
Question code
export const VendorMachine = ({
ballRadius,
gravity,
density,
drag,
onButtonClick,
}) => {
const canvasRef = React.useRef()
const { intersection, setIntersectionRef } = useIntersection({
threshold: 0.5,