Skip to content

Instantly share code, notes, and snippets.

View Bviveksingh's full-sized avatar
🙂
Focusing

Vivek Singh Bisht Bviveksingh

🙂
Focusing
View GitHub Profile
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 18:26
define variable paragraphArr
const [paragraphArr, setParagraphArr] = useState<JSX.Element[]>([]);
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 18:25
conditional rendering of Paragraph
{paragraphArr.length > 0 && <Paragraph/>}
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 18:21
define difficultyLevel variable
const [difficultyLevel, setDifficultyLevel] = useState<number | undefined>();
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 18:19
conditional rendering of difficultyLevel
{difficultyLevel === undefined && <DifficultyLevel />}
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 18:17
pages/main/index.tsx define variable timeInSeconds
const [timeInSeconds, setTimeInSeconds] = useState<number>();
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 18:15
pages/main/index.tsx
{timeInSeconds as number > 0 ? <Timer/> : <Duration/>}
const handler = {
get: async (target, date) => {
if(target[date]){
return target[date];
}
else{
const dataRaw = await fetch(`https://api.nasa.gov/planetary/apod?api_key=${apiKey}&date=${date}`, {
method : "GET",
mode: 'cors',
});
@Bviveksingh
Bviveksingh / new_proxy.js
Created August 14, 2022 11:43
new proxy object
const proxyObj = new Proxy(getTargetObj(), handler);
@Bviveksingh
Bviveksingh / setter_method_proxy.js
Last active August 14, 2022 10:13
setter method for proxy
const handler = {
set: function (target, property, value){
if(property === "age"){
if(typeof value == "string"){
alert("Cannot assign String to age, use Number only");
}
else{
target[property] = value;
}
}
@Bviveksingh
Bviveksingh / get_method_proxy.js
Created August 14, 2022 09:45
writing get method
const handler = {
get: function(target,property) {
if(property === "name"){
return `Name of the person is ${target[property]}`
}
},
}