Skip to content

feat(react): add useModel hook#200

Merged
manzt merged 1 commit into
mainfrom
useModel
Jul 22, 2023
Merged

feat(react): add useModel hook#200
manzt merged 1 commit into
mainfrom
useModel

Conversation

@manzt

@manzt manzt commented Jul 21, 2023

Copy link
Copy Markdown
Owner

Adds a hook to grab the model. Can be useful to subscribe to custom messages:

import * as React from "react";
import { createRender, useModel } from "@anywidget/react";

export let render = createRender(() => {
  let model = useModel();
  let [data, setData] = React.useState(null);

  React.useEffect(() => {
    let callback = (msg) => setData(msg);
    model.on("msg:custom", callback);
    return () => model.off("msg:custom", callback);
  }, [model]);

  if (!data) return null;
  return <pre>JSON.stringify(data)</pre>;
});

@netlify

netlify Bot commented Jul 21, 2023

Copy link
Copy Markdown

Deploy Preview for anywidget canceled.

Name Link
🔨 Latest commit bf06366
🔍 Latest deploy log https://app.netlify.com/sites/anywidget/deploys/64bae10f8d710300081a52e8

@manzt manzt changed the title feat(react): add hook feat(react): add useModel hook Jul 21, 2023
@codecov

codecov Bot commented Jul 21, 2023

Copy link
Copy Markdown

Codecov Report

Merging #200 (bf06366) into main (c48b829) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #200   +/-   ##
=======================================
  Coverage   98.11%   98.11%           
=======================================
  Files           8        8           
  Lines         424      424           
=======================================
  Hits          416      416           
  Misses          8        8           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@manzt
manzt merged commit 9a7bbbd into main Jul 22, 2023
@manzt
manzt deleted the useModel branch July 22, 2023 18:28
@github-actions github-actions Bot mentioned this pull request Jul 22, 2023
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

Successfully merging this pull request may close these issues.

1 participant