Skip to content

Commit

Permalink
docs(post-message): update using-a-post-message (#92)
Browse files Browse the repository at this point in the history
* chore(docs): update using-a-post-message

* docs: Update docs/using-a-post-message.md

Co-authored-by: Sungyu Kang <[email protected]>

---------

Co-authored-by: Sungyu Kang <[email protected]>
  • Loading branch information
ehddud1006 and gronxb authored Dec 21, 2024
1 parent 12c21cc commit 99c96bd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/using-a-post-message.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ import { createWebView, postMessageSchema } from "@webview-bridge/react-native";
const appPostMessageSchema = postMessageSchema({
eventName1: {
validate: (data) => data as string, // This is not recommended; please use validation libraries like zod or valibot.

},
eventName2: {
validate: (value) => data as { message: string }, // This is not recommended; please use validation libraries like zod or valibot.
validate: (data) => data as { message: string }, // This is not recommended; please use validation libraries like zod or valibot.
},
});

Expand Down Expand Up @@ -116,7 +115,7 @@ import * as v from "valibot";
const appPostMessageSchema = postMessageSchema({
eventName1: {
validate: (data) => {
return v.parse(v.string(), value);
return v.parse(v.string(), data);
}
},
eventName2: {
Expand All @@ -137,10 +136,11 @@ export const { postMessage } = createWebView({
});

// usage
postMessage("eventName1", {

postMessage("eventName1", "test");
postMessage("eventName2", {
message: "test",
});
postMessage("eventName2", "test");
```

:::
Expand All @@ -160,14 +160,14 @@ const bridge = linkBridge<AppBridge, AppPostMessageSchema>({
// ..
});

const unsubscribe = bridge.addEventListener("eventName1", (data) => {
window.alert(data.message);
const unsubscribe = bridge.addEventListener("eventName1", (message) => {
window.alert(message);
});
unsubscribe(); // Unsubscribe from the event


const unsubscribe2 = bridge.addEventListener("eventName2", (message) => {
window.alert(message);
const unsubscribe2 = bridge.addEventListener("eventName2", (data) => {
window.alert(data.message);
});
unsubscribe2(); // Unsubscribe from the event
```
Expand Down

0 comments on commit 99c96bd

Please sign in to comment.