concept return in category react

appears as: return, returns
React Hooks in Action

This is an excerpt from Manning's book React Hooks in Action.

function MyComponent ( props ) {
  // Use local state.
  const [value, setValue] = useState(initialValue);                #A
  const [state, dispatch] = useReducer(reducer, initialState);     #A
 
  useEffect(() => {
    // Perform side effect.                                        #B
  });
 
  return (
    <p>{value} and {state.message}</p>                             #C
  );
}
Listing 5.3 Resizing the window
import React, { useState, useEffect } from "react";
 
export default function WindowSize () {
  const [ size, setSize ] = useState(getSize());
 
  function getSize () {
    return {
      width: window.innerWidth,
      height: window.innerHeight
    };
  }
 
  useEffect(() => {
    function handleResize () {
      setSize(getSize());
    }
 
    window.addEventListener('resize', handleResize);
 
    return () => window.removeEventListener('resize', handleResize);    #A
  }, []);
 
 
  return <p>Width: {size.width}, Height: {size.height}</p>
};