I want to return nothing if a context variable is set to none.
But I get unexpected token on if?
return (
<AppContext.Consumer>
{context => (
if(context.objects[0] !== "none")
return;
<ul>
{context.objects.map((object, key) => {
return <li key={key}>{object.type}
//--- snip ----
Edit: The whole (working) component code is like this
const ObjectList = (props) => {
return (
<AppContext.Consumer>
{context => (
<ul>
{context.objects.map((object, key) => {
return <li key={key}>{object.type}
<Button
key={key}
style={{backgroundColor: "red"}}
onClick={() => context.deleteObject(key)}
>
x
</Button>
</li>
})}
</ul>
)}
</AppContext.Consumer>
);
}
But this always renders 1 li element because objects has "none" as an element when it gets initialized in the context provider:
const [objects, setObjects] = useState(['none']);
I want the list only be drawn, when there is something else than "none" in the objects array.