Skip to content

Instantly share code, notes, and snippets.

View chetanraj's full-sized avatar
🎯
Focusing

Chetan chetanraj

🎯
Focusing
View GitHub Profile
class Operation {
constructor(a, b) {
this.a = a
this.b = b
}
getSum() {
return this.a + this.b
}
}
let user = null;
let age = 12;
let isTeenage = user?.[value++];
console.log('isTeenage :: ', isTeenage);
// Output
isTeenage :: undefined
export const nameStateAtom = atom({
key: "nameStateAtom", // an unique id
default: "", // default value
});
const Input = () => {
const [name, setName] = useRecoilState(nameStateAtom);
const onChange = (event) => {
setName(event.target.value);
};
return (
<div className="input">
<input placeholder="Enter name" type="text" value={name} onChange={onChange} /><br />
export const nameStateSelector = selector({
key: "nameStateSelector", // unique ID
get: ({ get }) => {
const text = get(nameStateAtom);
return text;
},
});
import {atom, selector, useRecoilValue} from 'recoil';
const nameStateAtom = atom({
key: 'nameStateAtom',
default: ''
});
const nameStateSelector = selector({
key: 'nameStateSelector',
get: ({get}) => get(nameStateAtom)
});
{
"name": "app-name",
"version": "0.0.1",
"dependencies": { },
"devDependencies": { }
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
@chetanraj
chetanraj / Create.js
Created October 8, 2020 10:04
../pages/Create/index.js
import React from 'react';
import { useName } from '../logics/useName';
const Create = () => {
const { name, setName } = useName();
const onChange = e => {
setName(e.target.value);
};
@chetanraj
chetanraj / useName.js
Created October 8, 2020 10:05
../logics/useName.js
import React, { useState } from 'react';
const useName = () => {
const [name, setValue] = useState('');
const setName = name => {
setValue(name);
};
return { name, setName };
export const theme = {
breakpoints: [32, 48, 64],
space: [0, 4, 8, 16, 24, 32, 48, 64, 128, 256, 512],
fontSizes: [12, 14, 16, 18, 20, 24, 36, 48, 80, 96],
fontWeights: [100, 200, 300, 400, 500, 600, 700, 800, 900],
lineHeights: {
normal: 1,
title: 1.25,
paragraph: 1.5
},