I am trying to add a JSX variable to a page. I first initialized it as null because it may be potentially unused, but I want to add the JSX to the page if an event is triggered. The handler is executed once the user finishes text input and closes a modal window. I can successfully get their text up to this handler function below, but for some reason the variable's JSX is not being reflected on the current page after the modal is closed.
let other = null;
const handler = (text) => {
other = (
<li>
<span className="bold">Other: </span>
{text}}<span className="right">Price Unknown</span>
</li>
);
};
Later, I simply use this variable in my JSX
<div className="other">
{other}
</div>
Why exactly isn't this update reflecting on the page after the modal is closed? Where I expect the newly added list element to be, it's blank as if {other} is still referring to null. Is this an issue with the page needing to rerender?