It is only safe to omit a function from the dependency list if nothing in it (or the functions called by it) references props, state, or values derived from them. This example has a bug:

function ProductPage({ productId }) {
  const [product, setProduct] = useState(null);

  async function fetchProduct() {
    const response = await fetch('http://myapi/product/' + productId); // Uses productId prop    const json = await response.json();
    setProduct(json);
  }

  useEffect(() => {
    fetchProduct();
  }, []); // 🔴 Invalid because `fetchProduct` uses `productId`  // ...
}
The recommended fix is to move that function inside of your effect. That makes it easy to see which props or state your effect uses, and to ensure they’re all declared:

function ProductPage({ productId }) {
  const [product, setProduct] = useState(null);

  useEffect(() => {
    // By moving this function inside the effect, we can clearly see the values it uses.    async function fetchProduct() {      const response = await fetch('http://myapi/product/' + productId);      const json = await response.json();      setProduct(json);    }
    fetchProduct();
  }, [productId]); // ✅ Valid because our effect only uses productId  // ...
}
It’s difficult to remember which props or state are used by functions outside of the effect. This is why usually you’ll want to declare functions needed by an effect inside of it. Then it’s easy to see what values from the component scope that effect depends on:

function Example({ someProp }) {
  useEffect(() => {
    function doSomething() {
      console.log(someProp);    }

    doSomething();
  }, [someProp]); // ✅ OK (our effect only uses `someProp`)}
If after that we still don’t use any values from the component scope, it’s safe to specify []:

useEffect(() => {
  function doSomething() {
    console.log('hello');
  }

  doSomething();
}, []); // ✅ OK in this example because we don't use *any* values from component scope
If for some reason you can’t move a function inside an effect, there are a few more options:

function ProductPage({ productId }) {
  // ✅ Wrap with useCallback to avoid change on every render  const fetchProduct = useCallback(() => {    // ... Does something with productId ...  }, [productId]); // ✅ All useCallback dependencies are specified
  return <ProductDetails fetchProduct={fetchProduct} />;
}

function ProductDetails({ fetchProduct }) {
  useEffect(() => {
    fetchProduct();
  }, [fetchProduct]); // ✅ All useEffect dependencies are specified
  // ...
}
This also allows you to handle out-of-order responses with a local variable inside the effect:

useEffect(() => {
    let ignore = false;    async function fetchProduct() {
      const response = await fetch('http://myapi/product/' + productId);
      const json = await response.json();
      if (!ignore) setProduct(json);    }

    fetchProduct();
    return () => { ignore = true };  }, [productId]);
Generally speaking, no.

function Example({ someProp }) {
  function doSomething() {
    console.log(someProp);  }

  useEffect(() => {
    doSomething();
  }, []); // 🔴 This is not safe (it calls `doSomething` which uses `someProp`)}

Recommend

React Hooks FAQ Performance Optimizations Is it safe to omit functions from the list of dependencies?

React Hooks FAQ From Classes to Hooks How can I measure a DOM node?

React Hooks FAQ From Classes to Hooks Is there something like forceUpdate?

React Hooks FAQ From Classes to Hooks How do I implement getDerivedStateFromProps?

React Hooks FAQ From Classes to Hooks Why am I seeing stale props or state inside my function?

React Hooks FAQ From Classes to Hooks How to get the previous props or state?

React Hooks FAQ From Classes to Hooks Should I use one or many state variables?

React Hooks FAQ From Classes to Hooks Is there something like instance variables?

React Hooks FAQ Adoption Strategy How to test components that use Hooks?

React Forms Controlled Input Null Value

React Forms Handling Multiple Inputs

React Forms The file input Tag

React Forms The select Tag

React Forms The textarea Tag

React Forms Controlled Components

React Forms

Thinking in React Start With A Mock

React Typechecking With PropTypes Function Components

React Typechecking With PropTypes Default Prop Values

React Typechecking With PropTypes Requiring Single Child

React Typechecking With PropTypes PropTypes

React Typechecking With PropTypes

React Lifting State Up Lifting State Up

React Lifting State Up Writing Conversion Functions

React Lifting State Up Adding a Second Input

React Lifting State Up

ReactDOM Reference createPortal()

ReactDOM Reference findDOMNode()

ReactDOM Reference unmountComponentAtNode()

ReactDOM Reference hydrate()

ReactDOM Reference render()

React Release Channels Next Channel Using the Next Channel for Integration Testing

React Uncontrolled Components The file input Tag

React Uncontrolled Components Default Values

React Uncontrolled Components

React CDN Links Why the crossorigin Attribute?

React CDN Links

React Forwarding Refs Displaying a custom name in DevTools

React Forwarding Refs Forwarding refs in higher-order components

React Forwarding Refs Forwarding refs to DOM components

React Using the Effect Hook Tips for Using Effects Tip: Optimizing Performance by Skipping Effects

React Using the Effect Hook Tips for Using Effects Explanation: Why Effects Run on Each Update

React Using the Effect Hook Tips for Using Effects Tip: Use Multiple Effects to Separate Concerns

React Using the Effect Hook Recap

React Using the Effect Hook Effects with Cleanup Example Using Hooks

React Using the Effect Hook Effects with Cleanup Example Using Classes

React Using the Effect Hook Effects Without Cleanup Detailed Explanation

React Using the Effect Hook Effects Without Cleanup Example Using Hooks

React Using the Effect Hook Effects Without Cleanup Example Using Classes

React Using the Effect Hook

React Hooks API Reference Additional Hooks useDebugValue Defer formatting debug values

React Hooks API Reference Additional Hooks useDebugValue

React Hooks API Reference Additional Hooks useImperativeHandle

React Hooks API Reference Additional Hooks useRef

React Hooks API Reference Additional Hooks useMemo