File size: 750 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use client'

import { useContext } from 'react'
import { action, redirectAction } from './actions'
import { DataContext } from './context'

export function Button() {
  const { setData } = useContext(DataContext)
  const handleClick = async () => {
    await new Promise((res) => setTimeout(res, 1000))

    const result = await action()

    setData(result)
  }

  const handleRedirect = async () => {
    await new Promise((res) => setTimeout(res, 1000))

    const result = await redirectAction()

    setData(result)
  }

  return (
    <>
      <button onClick={handleClick} id="run-action">
        Run Action
      </button>

      <button onClick={handleRedirect} id="run-action-redirect">
        Run Redirect
      </button>
    </>
  )
}