This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Child({ name, shouldScrollTo }) { | |
| const ref = useRef() | |
| useEffect(() => { | |
| shouldScrollTo && ref.current.scrollIntoView({behavior: "smooth"}); | |
| }, []); | |
| return <div ref={ref}>{name}</div>; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function Parent() { | |
| const [items, setItems] = useState([]); | |
| const firstNewItemIndex = useRef(); | |
| const handleSetItems = () => { | |
| setItems((prevItems) => { | |
| firstNewItemIndex.current = prevItems.length + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`, | |
| })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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], |
NewerOlder