React use.Effect not triggering
12:21 25 Nov 2025

I'm trying to create a custom hook to load information about a specific asset but that doesn't work even though everything is set up correctly.

I already tried to log within the useEffect callback function but nothing seems to appear.

export default function useAsset(assetId, someProp){
    // Define the asset state
    const [ asset, setAsset ] = useState({});

    // Load asset information only when a new asset id appears
    useEffect(() => {
        // Load asset information from the backend
        const assetInfo = getAssetById(assetId);
        
        // Set the new state
        setAsset(assetInfo);

        // Update the graphics on the page
        foo(assetInfo.state, someProp);
    }, [assetId, customerView]);

    // Return an array containing both the ticket and the function that triggers its change
    return [
        asset,
        setAsset
    ];
}

// Component calling the custom hook
function Component({ assetId, someProp }) {
    // Define the current state of the asset
    const [ asset, loadAsset ] = useAsset(Number(assetId), false);

    ...
}
reactjs react-hooks react-custom-hooks