Error: `FileSystem.moveAsync` needs a `to` path. in react native (Expo)

Solution 1:

It must be because setState() is asynchronous so when you try to set to to newPathImage it's still undefined. It should work if you do something like this instead:

const fileMoveHandler = async () => {
    const fileName = selectedImage.split("/").pop();
    const newPathImage = FileSystem.documentDirectory + fileName
    console.log("FileSystem:", newPathImage);
    setNewPathImage(newPathImage);
    console.log("newPathImage", newPathImage);
    try {
      await FileSystem.moveAsync({
        from: selectedImage,
        to: newPathImage,
      });
    } catch (err) {
      console.log("Error:", err);
      Alert.alert("Can't move this file.", "Try again!", [{ text: "Okay" }]);
    }
  };