I have a function named getAllEmployees which I export from another file.
const getAllEmployees = () => {
return [1,2,3,4,5,6,7,8,9]
}
export { getAllEmployees }
now I use React.useState(getAllEmployees). this gives me the result, when I call like React.useState(getAllEmployees()) it also gives me same result, event when call like React.useState(() => getAllEmployees()) this also gives me the same result.
import here
import { getAllEmployees } from './Service/Service'
use with useState
const [result] = useState(getAllEmployees ) or
const [result] = useState(getAllEmployees()) or
const [result] = useState(() => getAllEmployees())
console.log(result)
for all of those result is
(9) [1, 2, 3, 4, 5, 6, 7, 8, 9]
My question is why they gives me same results, and which is the right way?