Skip to content

Instantly share code, notes, and snippets.

@jacobdo2
jacobdo2 / Child.js
Last active November 28, 2021 08:02
function Child({ name, shouldScrollTo }) {
const ref = useRef()
useEffect(() => {
shouldScrollTo && ref.current.scrollIntoView({behavior: "smooth"});
}, []);
return <div ref={ref}>{name}</div>;
}
function Child({ name }) {
const ref = useRef()
useEffect(() => {
// When no dependencies are passed to the useEffect hook
// it will run only once when mounted
}, []);
return <div ref={ref}>{name}</div>;
}
export default function Parent() {
const [items, setItems] = useState([]);
const firstNewItemIndex = useRef();
const handleSetItems = () => {
setItems((prevItems) => {
firstNewItemIndex.current = prevItems.length + 1
export default function Parent() {
const [items, setItems] = useState([]);
const handleSetItems = () => {
setItems((prevItems) => {
return [
...prevItems,
...new Array(10).fill("").map((_, index) => ({
name: `Some item ${index + prevItems.length}`,
}))
import React from "react";
import _ from "lodash";
const search = _.debounce((value) => console.log(value), 500);
export default function SearchPage() {
const [inputValue, setInputValue] = React.useState("");
React.useEffect(() => {
search(inputValue);
import React from "react";
export default function SearchPage() {
const [inputValue, setInputValue] = React.useState("");
return (
<input
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { AuthConfig } from './auth.config';
import { PassportModule } from '@nestjs/passport';
import { JwtStrategy } from './jwt.strategy';
@Module({
imports: [PassportModule.register({ defaultStrategy: 'jwt' })],
providers: [AuthConfig, AuthService, JwtStrategy],
import { Controller, Get, UseGuards } from '@nestjs/common';
import { AppService } from './app.service';
import { AuthGuard } from '@nestjs/passport';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
@UseGuards(AuthGuard('jwt'))
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { AuthService } from './auth.service';
import { passportJwtSecret } from 'jwks-rsa';
import { AuthConfig } from './auth.config';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { AuthConfig } from './auth.config';
import { PassportModule } from '@nestjs/passport';
@Module({
imports: [PassportModule.register({ defaultStrategy: 'jwt' })],
providers: [AuthConfig, AuthService],
controllers: [AuthController],