From 99c96bdc98189b05cfefebaebaa66c5cbfb29900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=8F=99=EC=98=81?= Date: Sun, 22 Dec 2024 00:13:28 +0900 Subject: [PATCH] docs(post-message): update using-a-post-message (#92) * chore(docs): update using-a-post-message * docs: Update docs/using-a-post-message.md Co-authored-by: Sungyu Kang --------- Co-authored-by: Sungyu Kang --- docs/using-a-post-message.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/using-a-post-message.md b/docs/using-a-post-message.md index d365ea0..d08af3d 100644 --- a/docs/using-a-post-message.md +++ b/docs/using-a-post-message.md @@ -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. }, }); @@ -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: { @@ -137,10 +136,11 @@ export const { postMessage } = createWebView({ }); // usage -postMessage("eventName1", { + +postMessage("eventName1", "test"); +postMessage("eventName2", { message: "test", }); -postMessage("eventName2", "test"); ``` ::: @@ -160,14 +160,14 @@ const bridge = linkBridge({ // .. }); -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 ```