Skip to content

v.1.2.0

Choose a tag to compare

@azjgard azjgard released this 20 Sep 00:38
· 17 commits to main since this release

Feature Additions

Hooks

  • Expose hooks-based API being used internally. Rationale explained in #16 (comment):

A public hooks-based API for library consumers to use has been on our roadmap for quite some time, but we haven't yet gotten around to implementing it. The hooks that ditto-react uses internally have some ergonomic rough edges due to how they've evolved from legacy constraints, which is why those haven't always been exported alongside the associated React components.

Although we still expect to release a better-designed hooks API in the future, I think it makes total sense to allow usage of the existing (currently internal) hooks until then -- as mentioned in #13 (comment), we just want to make sure we get things right before advocating for people to adopt them.

import { useDittoComponent, useDittoSingleText } from "ditto-react";

const SomePage = () => {
  // consume text synced from components in a Ditto component library
  const componentText: string | null = useDittoComponent({ componentId: "xxx-xxx-xxx" });

  // consume text synced from text items in a Ditto project
  const text: string | null = useDittoSingleText({ textId: "xxx-xxx-xxx" });
  ...
}

See the README for more information.

Thanks to @dgreene1, @VladymyrPylypchatin, @JeffBaumgardt, and others for advocating for the change.

Miscellaneous

  • General cleanup of types to accommodate hooks being used directly