Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive UI updates are not working at all #8

Open
Tibz-Dankan opened this issue Nov 7, 2024 · 0 comments
Open

Reactive UI updates are not working at all #8

Tibz-Dankan opened this issue Nov 7, 2024 · 0 comments

Comments

@Tibz-Dankan
Copy link

Tibz-Dankan commented Nov 7, 2024

export const someForm = () => {
  const [alert, setAlert] = useState({ type: "", message: "" });
 
  const submitHandler = async () => {
    try {
      // Make actual API call here
      setAlert({
        type: "success",
        message: "some response message from api call",
      });
    } catch (error) {
      setAlert({ type: "error", message: error.message });
    }
  };

  const UI = html`<div>
    <form>
      <div>
        ${alert.current().message &&
        html`<div>
          ${Alert({
            type: alert.current().type,
            message: alert.current().message,
          })}
        </div>`}
      </div>
      <button type="button" onClick="${submitHandler}">Submit</button>
    </form>
  </div>`;

  return reactive(() => UI);
};

The code tries to show an alert message based on the API response but it is not shown upon response. The alert variable updates to the latest value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant