Skip to content

Instantly share code, notes, and snippets.

View maskaravivek's full-sized avatar
💭
Active!

Vivek Kumar Maskara maskaravivek

💭
Active!
View GitHub Profile
async function refreshAccessToken(token) {
try {
const refreshedTokensResponse = await fetch("https://cognito-idp.us-west-2.amazonaws.com", {
headers: {
"X-Amz-Target": "AWSCognitoIdentityProviderService.InitiateAuth",
"Content-Type": "application/x-amz-json-1.1",
},
method: "POST",
body: JSON.stringify({
"AuthFlow": "REFRESH_TOKEN_AUTH",
// pages/api/auth/[...nextauth].js
import NextAuth from "next-auth"
import CognitoProvider from "next-auth/providers/cognito";
export const authOptions = {
providers: [
CognitoProvider({
clientId: process.env.COGNITO_CLIENT_ID,
clientSecret: process.env.COGNITO_CLIENT_SECRET,
issuer: process.env.COGNITO_DOMAIN,
import React, { useState, useEffect } from 'react';
function Example() {
const [count, setCount] = useState(0);
// Similar to componentDidMount and componentDidUpdate:
useEffect(() => {
// Update the document title using the browser API
document.title = `You clicked ${count} times`;
});
import React, { useState } from 'react';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>

Tips for Optimizing Performance when Using React Hooks

React Hooks are a great way to manage state and side effects in React components, but they can also cause performance issues if used incorrectly. This article will provide some tips on how to optimize performance when using React Hooks.

Using the Effect Hook – React

Use the useEffect Hook

The useEffect Hook is a great way to manage side effects in React components. It allows you to perform side effects without having to manually manage the component lifecycle. It also allows you to optimize performance by only running the side effects when certain conditions are met.

Tips for Optimizing Performance when Using React Hooks

React Hooks are a great way to manage state and side effects in React components, but they can also cause performance issues if used incorrectly. This article will provide some tips on how to optimize performance when using React Hooks.

Using the Effect Hook – React

Use the useEffect Hook

The useEffect Hook is a great way to manage side effects in React components. It allows you to perform side effects without having to manually manage the component lifecycle. It also allows you to optimize performance by only running the side effects when certain conditions are met.

Tips for Optimizing Performance when Using React Hooks

React Hooks are a great way to manage state and side effects in React components, but they can also cause performance issues if used incorrectly. This article will provide some tips on how to optimize performance when using React Hooks.

Using the Effect Hook – React

Use the useEffect Hook

The useEffect Hook is a great way to manage side effects in React components. It allows you to perform side effects without having to manually manage the component lifecycle. It also allows you to optimize performance by only running the side effects when certain conditions are met.

async function pushChangesToGithub(
githubAccessToken,
commitTitle,
githubRepoFullName,
githubRepoBranchName
) {
try {
const articleFiles = [
{
path: "/my-new-website/index.html",
[
{
"path": "/my-new-website/index.html",
"content": "Hello World!",
"encoding": "utf-8"
},
{
"path": "/my-new-website/images/logo.png",
"content": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQ",
"encoding": "base64"
const createGithubCommit = async (
githubAccessToken,
repoFullName,
branchName,
commitMessage,
articleFiles
) => {
const tree = await createGithubRepoTree(
githubAccessToken,
repoFullName,