首页 > 其他分享 >useCallback

useCallback

时间:2023-03-20 10:57:35浏览次数:40  
标签:function referrer useCallback dependencies fn productId

useCallback is a React Hook that lets you cache a function definition between re-renders

const cachedFn = useCallback(fn, dependencies)

Reference

useCallback(fn, dependencies)

Call useCallback at the top level of your component to cache a function definition between re-renders

import { useCallback } from 'react';

export default function ProductPage({ productId, referrer, theme }) {
  const handleSubmit = useCallback((orderDetails) => {
    post('/product/' + productId + '/buy', {
      referrer,
      orderDetails,
    });
  }, [productId, referrer]);

Parameters

  • fn:
  • dependencies:

Returns

Caveats

标签:function,referrer,useCallback,dependencies,fn,productId
From: https://www.cnblogs.com/jun-jiang/p/17235517.html

相关文章