I have a very long string that is over 1000 characters. I was just wondering if I could store that in the state without any problems. Also, I want to add this long string with a fairly short string. Will that be possible.
FYI: I am using useState
from React hooks. Also, I am in react native, but I don't know if it changes anything.
EDIT: I am writing this question because when I store it in the state, then print it out, it console.log
as undefined
.
Here is my code:
const exportReport = async () => {
if (validate()) {
setLoading(true);
let token = await SecureStore.getItemAsync("token");
return await fetch("https://notarealapi.herokuapp.com/api/export", {
method: "POST",
headers: {
"content-type": "application/json",
Authorization: `JWT ${JSON.parse(token)}`,
},
body: JSON.stringify({ note: note, mission: value }),
})
.then((res) => res.json())
.then(async (json) => {
if (json.hasOwnProperty("msg")) {
Alert.alert(json.msg);
} else {
setLoading(false);
console.log(json);
setReportUrl("data:application/pdf;base64," + String(json.pdf));
console.log(reportUrl);
const base64Code = reportUrl.split(
"data:application/pdf;base64,"
)[1];
const filename = FileSystem.documentDirectory + "report.pdf";
console.log(base64Code);
await FileSystem.writeAsStringAsync(filename, base64Code, {
encoding: FileSystem.EncodingType.Base64,
});
const _mediaResult = await MediaLibrary.saveToLibraryAsync(
filename
);
await Sharing.shareAsync(filename);
}
})
.catch((error) => console.error(error));
}
};
Any help will be appreciated.
Thank you