score:0

Accepted answer

by simplifying your code a little bit (mostly just removing the sorts function from the body of your code and cleaning up the useeffect hook), i was able to get it to work

import { usestate, useeffect } from "react";

function sorts(firstarr, secondarr) {
  let c = [...firstarr, ...secondarr];
  return c.sort();
}

export default function app() {
  const [sorted, setsorted] = usestate([]);
  const a = [1, 3, 5];
  const b = [2, 4, 6];
  
useeffect(() => {
    let sortedarr = sorts(a, b);
    setsorted([...sortedarr]);
  }, []);

  return (
    <div classname="app">
      <h2>sorted array below</h2>
      <p>{json.stringify(sorted)}</p>
    </div>
  );
}

score:1

i've tried to replicate the error in a codesandbox, the only thing causing an error, was a missing paranthesis. however your code was really hacky and unnecessary long. this is cleaner and works: https://codesandbox.io/s/flamboyant-pasteur-c9c83?file=/src/app.js


Related Query

More Query from same tag