📦 @livepreso/content-react
App​
If you want to add a context manager (a Theming manager for example), you can add it here.
import React from "react";
import { App } from "@livepreso/content-react";
import { ThemeContext } from "your-library";
const app = App.run((Slide) => {
return (
<ThemeContext theme={{ yourTheme }}>
<Slide />
</ThemeContext>
);
});
export default app;
Hooks - General​
useSlideContext(path[, defaultValue])​
Retrieve and set (if using a path) context.
import React from "react";
import { useSlideContext } from "@livepreso/content-react";
export default function () {
// Retrieve the whole context as json
const [context] = useSlideContext();
// Update and return a nested path
const [name, setName] = useSlideContext("form.name", "John Doe");
return <div onClick={() => setName("Jane Doe")}>{name}</div>;
}
Internally this uses useSharedState
, so will affect remote presos in the same way.
useCMSVal(name, [{ enabled, slidePath }])​
Get/set global editables using a simple useState like interface.
Use enabled: false
to prevent it running when it shouldn't be accessible.
slidePath
can accept a slidePath like the ones used in
Bridge.Navigation.gotoSlide(), and will instead
all you to get/set the values for that slide.
// Assuming for this slide you have `editables: ["your-editable"]`
// in your project file
import React from "react";
import { useCMSVal } from "@livepreso/content-react";
export default function () {
const [name, setName] = useCMSVal("your-editable");
// Alternatively return values from another slide
// const [name, setName] = useCMSVal("your-editable", {
// slidePath: "{{deck}}/my-section/my-slide"
// });
return (
<div
style={{ pointerEvents: "initial" }}
onClick={() => setName("Jane Doe")}
>
{name}
</div>
);
}
When in presomanager mode, elements that need to be interactive should have pointer-events: initial
set, otherwise it can't be clicked.
usePrepEditable(editableKey)​
Gets and sets user editables (text modified in a preso as opposed to presomanager). If using the built-in editables, these would be used for data-editable. Think of prep editable as a per-preso editables, meant to be edited per preso created.
Takes care of placing it in the correct part of the context to deal with user templates,
so should be used over useSlideContext
if using on a template.
import React from "react";
import { usePrepEditable } from "@livepreso/content-react";
export default function () {
const [value, setValue] = usePrepEditable("your-editable");
return <input value={value} onChange={(e) => setValue(e.target.value)} />;
}