Skip to content

Instantly share code, notes, and snippets.

View dandelionadia's full-sized avatar
👾

Nadiia Ridko dandelionadia

👾
  • Prague, Czech Republic
View GitHub Profile
import React, { useEffect, useRef, useContext } from "react";
import { AuthContext } from "../../context/auth-context";
export const Cockpit = (props) => {
const authContext = useContext(AuthContext);
console.log(authContext.authenticated);
return (
<>
class Person extends Component {
constructor(props) {
super(props);
this.inputElementRef = React.creatRef();
}
componentDidMount() {
this.inputElementRef.current.focus();
}
import React, { useEffect, useRef } from "react";
interface CockpitProps {
onClick: any;
persons: any[];
personsLength: any;
}
export const Cockpit: React.FC<CockpitProps> = React.memo(props => {
const toggleBtnRef = useRef<HTMLButtonElement>(null);
state = {
persons: [
{ id: 'asfa1', name: 'Max', age: 28 },
{ id: 'vasdf1', name: 'Manu', age: 29 },
{ id: 'asdf11', name: 'Stephanie', age: 26 }
],
otherState: 'some other value',
showPersons: false,
showCockpit: true,
changeCounter: 0
useEffect(() => {
console.log("[Cockpit.js] useEffect");
const timer = setTimeout(() => {
alert("foo time out");
}, 1000);
return () => {
clearTimeout(timer);
};
}, []);
@dandelionadia
dandelionadia / ProductPage
Last active March 19, 2020 15:04
Building React Hook + TypeScript
export interface ProductData {
id: string
title: string
description: string
rating: number
price: number
images: string[]
relatedProducts: string[]
shopAttributes: ProductAttributes[]
reviews: ProductReview[]
@dandelionadia
dandelionadia / styles.scss
Created February 5, 2020 20:20 — forked from kettanaito/styles.scss
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;
const Toggle = () => {
const [isToggle, setIsToggle] = React.useState(true)
const handleClick = () => {
setIsToggle(!isToggle)
}
return (
<button onClick={handleClick}>{isToggle ? 'On' : 'Off'}</button>
)
@dandelionadia
dandelionadia / FluidVideo.css
Created November 7, 2019 09:44
Fluid Width Video
```css
.videoWrapper {
position: relative;
padding-bottom: 56.25%; /* 16:9 */
padding-top: 25px;
height: 0;
}
.videoWrapper iframe {
position: absolute;
top: 0;
@dandelionadia
dandelionadia / Search.jsx
Created October 4, 2019 14:05
react functional component debounce
import React, { useState, useRef } from 'react'
import debounce from 'lodash.debounce'
const Search = () => {
// state text which was written in the input
const [value, setValue] = useState('')
// using "useRef" so that React doesn't create
// debounced function on each render (after state update).
const doSearch = useRef(