S
SolidJS11mo ago
d34dbug

Right side of assignment cannot be destructured

This may not be a solid issue but I am really confused. I did not have this problem when I was using vanilla Javascript; however, switching to solidjs changed a massive amount of how the app functions. So I am trying build a tauri app and I have a command:
async function new_session({ name, temp }) {
let msg;
if (name) {
msg = {
name: name,
temp: temp
}
} else {
msg = { temp: temp }
}
console.log({ "msg": JSON.stringify(msg) })
let check = await invoke("new_session", { "msg": JSON.stringify(msg) })
return check
}
async function new_session({ name, temp }) {
let msg;
if (name) {
msg = {
name: name,
temp: temp
}
} else {
msg = { temp: temp }
}
console.log({ "msg": JSON.stringify(msg) })
let check = await invoke("new_session", { "msg": JSON.stringify(msg) })
return check
}
This is the button that should execute that command:
<button
onClick={async (e) => {
e.preventDefault();
switch(selectedOption()){
case "temp_session":
let x = await new_session();
console.log("x: ",x);
break;
default:
console.log("choose a session");
};
console.log("selected option:", selectedOption());
}}
>
<button
onClick={async (e) => {
e.preventDefault();
switch(selectedOption()){
case "temp_session":
let x = await new_session();
console.log("x: ",x);
break;
default:
console.log("choose a session");
};
console.log("selected option:", selectedOption());
}}
>
In vanilla javascript the command could be executed fine. However, I created a solid version so the app might be a little easier to reason through. All my commands got added to a commands.jsx file and the commands should get imported to get used. So i'm exporting the function from commands and importing it into the module I need to use it in. However, when I press the button that should execute it I get the error: Unhandled Promise Rejection: TypeError: Right side of assignment cannot be destructured I have absolutely no idea why it's broken, why it thinks it's destructuring something and how I might go about fixing it. Can someone give me some insight?
4 Replies
bigmistqke
bigmistqke11mo ago
my guess: new_session({ name, temp }) has as signature {name, temp} but in the button you pass it nothing new_session() not sure why this would work in vanilla
d34dbug
d34dbugOP11mo ago
Thank you for that. Definitely an oversight from copying it over. However, how would that lead to the error I'm receiving? I could see an error telling me that parameters are missing or something, but the error doesn't seem to line up with that. Just a bad error message? Unfortunately I won't have time to work on it until maybe tomorrow to test if that's the cause of the error.
bigmistqke
bigmistqke11mo ago
well, I think you could reason about it like const { name, temp } = undefined typescript is handy for these type of stuff
function new_session({ name, temp }) {}
// is short hand for
function new_session(arg){
const { name, temp } = arg
}
function new_session({ name, temp }) {}
// is short hand for
function new_session(arg){
const { name, temp } = arg
}
d34dbug
d34dbugOP11mo ago
That was the problem. Strange. Thanks. I should have seen that. I think what threw me was the error message which didn't seem to have anything to do with the actual error not providing parameters that are expected/required
Want results from more Discord servers?
Add your server