Openbravo Issue Tracking System - POS2
View Issue Details
0051504POS2POSpublic2023-01-30 12:382023-08-01 06:23
jorge-garcia 
Rajesh_18 
normalmajorhave not tried
scheduledopen 
5
 
 
No
0051504: Replace async useEffect references from the code with proper code
useEffect hook callback in React expects to return a function or nothing. Using reserved keyword async in useEffect hook callback returns instead a Promise.

Using async in useEffect callback raises a warning in web console and could cause future problems during the execution of the hook.
These are the occurrences I found so far in the code:

- ColorCellPopover.jsx
- KeymapEditorCategoryDialog.jsx
- ProductSelector.jsx
Imagine this is the code we have right now:
  const [state, setState] = useState(0);

  useEffect(async () => {
    const data = await getData()
    setState(data)
  }, []);


The idea is to change the code from this:
  const [state, setState] = useState(0);

  useEffect(() => {
    const fetchData = async()=> {
      const data = await getData()
      setState(data);
    };

    fetchData();
   }, []);

There is another alternative that is to implement the asynchronous function into a useCallback hook:
  const [state, setState] = useState(0);

  const fetchData = useCallback(async()=> {
    const data = await getData();

    setState(data);
  }, []);

  useEffect(() => {
    fetchData()
  }, [fetchData]);
No tags attached.
Issue History
2023-01-30 12:38jorge-garciaNew Issue
2023-01-30 12:38jorge-garciaAssigned To => Retail
2023-01-30 12:38jorge-garciaTriggers an Emergency Pack => No
2023-07-31 09:11sreehariAssigned ToRetail => Rajesh_18
2023-08-01 06:23Rajesh_18Statusnew => scheduled

There are no notes attached to this issue.