Skip to content

Instantly share code, notes, and snippets.

View hamettio's full-sized avatar
😎

Hamed Abdollahi hamettio

😎
  • Javascript World
View GitHub Profile
@hamettio
hamettio / LocalStorage.js
Created December 30, 2021 10:16
Handling localStorage setItem(), getItem(), removeItem(), and clear() in React.js
import React, { useState, useEffect } from "react";
const LocalStorage = () => {
const [welcome, setWelcome] = useState("");
// Checking if localStorage has a "hasVisited" key else we add "hasVisited" with "lastUpdate" to it
useEffect(() => {
if (localStorage.getItem("hasVisited")) {
setWelcome("Welcome Back!");
} else {
@hamettio
hamettio / Checkbox.js
Created December 27, 2021 09:21
Handling "checkbox" input in React.js with hooks
import React, { useState } from "react";
const Checkbox = () => {
const [checkbox, setCheckbox] = useState({
autoTrade: false,
atRiskPerTrade: "",
});
const { autoTrade, atRiskPerTrade } = checkbox;
@hamettio
hamettio / Radio.js
Last active January 18, 2022 09:30
Handling "radio" input in React.js with hooks
import React, { useState } from "react";
const Radio = () => {
const [radio, setRadio] = useState({
stoplossPercentage: "0.5",
});
const { stoplossPercentage } = radio;
const onChange = (e) => {
setRadio({ [e.target.name]: e.target.value });
@hamettio
hamettio / Select.js
Created December 27, 2021 09:07
Handling "select" input in React.js with hooks
import React, { useState } from "react";
const Select = () => {
const [select, setSelect] = useState({
tradeStatus: "",
});
const { tradeStatus } = select;
const onChange = (e) => {
setSelect({ tradeStatus: e.target.value });