Skip to content

Commit

Permalink
fix(react-exsample): fix postmessage processing in app
Browse files Browse the repository at this point in the history
  • Loading branch information
akim-muto committed Sep 29, 2024
1 parent 7919573 commit 648af76
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions examples/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { useState } from 'react';
import { vscodeWebview } from '@tomjs/vscode-webview';
import { VSCodeButton, VSCodeTextField } from '@vscode/webview-ui-toolkit/react';
import { vscode } from './utils/vscode';

import './App.css';

function App() {
function onPostMessage() {
vscodeWebview.postMessage('hello', 'Hey there partner! 🤠');
vscode.postMessage({
type: 'hello',
data: 'Hey there partner! 🤠' + message,
});
}

vscodeWebview.on('hello', data => {
console.log('on message:', data);
});

const [message, setMessage] = useState('');
const [state, setState] = useState('');

const onSetState = () => {
vscode.setState(state);
};
const onGetState = async () => {
setState((await vscode.getState()) as string);
const onGetState = () => {
setState(vscode.getState() as string);
};

return (
Expand Down

0 comments on commit 648af76

Please sign in to comment.