Skip to content

Instantly share code, notes, and snippets.

View chetanraj's full-sized avatar
🎯
Focusing

Chetan chetanraj

🎯
Focusing
View GitHub Profile
{
"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",
import {atom, selector, useRecoilValue} from 'recoil';
const nameStateAtom = atom({
key: 'nameStateAtom',
default: ''
});
const nameStateSelector = selector({
key: 'nameStateSelector',
get: ({get}) => get(nameStateAtom)
});
export const nameStateSelector = selector({
key: "nameStateSelector", // unique ID
get: ({ get }) => {
const text = get(nameStateAtom);
return text;
},
});
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 nameStateAtom = atom({
key: "nameStateAtom", // an unique id
default: "", // default value
});
let user = null;
let age = 12;
let isTeenage = user?.[value++];
console.log('isTeenage :: ', isTeenage);
// Output
isTeenage :: undefined
class Operation {
constructor(a, b) {
this.a = a
this.b = b
}
getSum() {
return this.a + this.b
}
}
let theValue;
if(response &&
response.data &&
response.data.answer &&
response.data.answer.value) {
theValue = response.data.answer.value;
} else {
theValue = 'JavaScript is BAE 💛❤️';
}
const response = {
"data": {
"query": "What is javascript ?",
"answer" : {
"value": "JavaScript is 💛"
}
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet"
type="text/css" />
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">