For clean code & folder structure, I'm moving some data (in this case, modal data) to a separate file. However, I'm not able to put a component inside an object value. Here's what I want to do:
export function invalidId(id) {
return {
info: {
title: "Invalid ID!",
message: (
<>
The
<code className="inline-code">{id}</code>
is invalid. Please make sure blah blah blah...
</>
),
},
// I need help with this part
buttons: {
<>
<Button label="Retry" />
<Button label="More Info" >
</>
}
}
}
import { invalidId } form "modaldata";
setModalInfo(invalidId(id).info);
setModalButtons(invalidId(id).buttons);
I used return here because id is dynamic. The main problem is buttons part. What is the correct way to put JSX inside an object?
(), you can just use the fragment directly, but people often do use()not least because they're used to doing it elsewhere because of thereturnsemicolon problem.) If you post an answer, please @ ping me and I'll adjust mine to call attention to yours.<>) on the same line asbuttons:. T.J. Crowder did this in one of the solutions, so I won't post an answer.