Jess
Jess
SSolidJS
Created by Jess on 4/2/2024 in #support
Ternary and Show have unequal output
In a basic Vite and Solid app, I have
const [page, setPage] = createSignal({
image: null,
timer: null,
choices: [],
notifications: [],
prompting: false,
awaiting_confirm: false,
} as Page, { equals: false })
// Some time later

{page().prompting ? <input type="text" value={promptInput()} onInput={(e) => setPromptInput(e.currentTarget.value)} onKeyPress={(event) => {
if (event.key === "Enter") {
engine.setPromptResponse(promptInput());
setPromptInput("");
}
}} /> : <></>}

<Show when={() => page().prompting}>
<p>I shouldn't be here</p>
</Show>
const [page, setPage] = createSignal({
image: null,
timer: null,
choices: [],
notifications: [],
prompting: false,
awaiting_confirm: false,
} as Page, { equals: false })
// Some time later

{page().prompting ? <input type="text" value={promptInput()} onInput={(e) => setPromptInput(e.currentTarget.value)} onKeyPress={(event) => {
if (event.key === "Enter") {
engine.setPromptResponse(promptInput());
setPromptInput("");
}
}} /> : <></>}

<Show when={() => page().prompting}>
<p>I shouldn't be here</p>
</Show>
But, "I shouldn't be here" is showing up, while the input (which was originally in place of the "I shouldn't be here") doesn't, as expected. Am I misunderstanding the When component or is it just interacting strangely? It hides the text when I put in a straight false, but not when I use a false reactive signal
52 replies