สร้าง custom global function ใน next-js

ตัวอย่างเราจะสร้าง folder lib แล้วสร้าง custom function ไว้ในนี้

เราจะสร้าง lib/utils.js แล้วก็สร้างฟังก์ชัน add

export function add(a, b) {
  return a + b;
}

จากนั้นเราก็จะเรียกได้แบบนี้

import { add } from '../lib/utils'

export default function MyPage() {
  const result = add(1, 2);
  return <p>{result}</p>
}


Copyright © 2023 Devcode Code Example - Powered by www.doesystem.com