Skip to content

Instantly share code, notes, and snippets.

import React, {useState} from 'react';
const App = () => {
const [fontSize, updateFontSize] = useState(14)
}
export default App
@adarsh0d
adarsh0d / useContext.js
Created May 5, 2020 10:07
useContext.js
import React, {useState, useContext} from 'react';
const Context = React.createContext()
const App = () => {
const [fontSize, updateFontSize] = useState(14);
return (
<Context.Provider value={{fontSize: fontSize, updateFontSize: (val) => updateFontSize(val)}}>
<Child1></Child1>
<Context.Provider>
@adarsh0d
adarsh0d / useContext1.js
Created May 5, 2020 10:18
useContextMultiple
import React, {useState, useContext} from 'react';
const Context = React.createContext()
const App = () => {
const [fontSize, updateFontSize] = useState(14);
const [fontFamily, updateFontFamily] = useState('Ariel');
const [text, updateText] = useState('Sample');
const providerVal = {
fontSize: fontSize,
updateFontSize: (val) => updateFontSize(val)
@adarsh0d
adarsh0d / useContext2.js
Last active May 5, 2020 10:38
Multi context
import React, {useState, useContext} from 'react';
const TextContext = React.createContext()
const FontContext = React.createContext()
const App = () => {
const [fontSize, updateFontSize] = useState(14);
const [fontFamily, updateFontFamily] = useState('Ariel');
const [text, updateText] = useState('Sample');
const textContext = {
text: text,
import React, {useState, useContext, useReducer} from 'react';
const TextContext = React.createContext()
const FontContext = React.createContext()
const App = () => {
const [state, dispatch] = useReducer((prevState, action) => {
switch (action.type) {
case 'UPDATE_FONT_FAMILY':
return {
import React, {useState, useContext, useMemo, useReducer} from 'react';
const TextContext = React.createContext()
const FontContext = React.createContext()
const App = () => {
const [state, dispatch] = useReducer((prevState, action) => {
switch (action.type) {
case 'UPDATE_FONT_FAMILY':
return {
@adarsh0d
adarsh0d / Sample.js
Created July 17, 2021 04:45
Convert react component to web component (antd component to web component)
import React from 'react'
import PropTypes from 'prop-types';
import { Button, DatePicker } from 'antd';
const Sample = (props) => {
console.log(props)
const { onbuttonpress, ...remainingProps } = props
return (
<DatePicker {...remainingProps} onChange={(date, dateString) => onbuttonpress({ detail: {date, dateString} })} />
)
}
@adarsh0d
adarsh0d / input.scss
Created August 31, 2021 10:05
Generated by SassMeister.com.
//variables
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}
//nesting
@adarsh0d
adarsh0d / input.scss
Created August 31, 2021 10:26
Generated by SassMeister.com.
//variables
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}
//nesting
@adarsh0d
adarsh0d / input.scss
Created August 31, 2021 10:28
Generated by SassMeister.com.
//variables
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}
//nesting