Skip to content

Commit

Permalink
Update README + example
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitch528 committed Jun 23, 2021
1 parent 1a613d9 commit d080c6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ npm install @mitch528/react-native-grpc

## Usage

```js
```ts
import { GrpcClient, GrpcMetadata } from '@mitch528/react-native-grpc';

GrpcClient.setHost('example.com');

// Bring your own protobuf library
// This example uses https://github.com/timostamm/protobuf-ts

const message = ExampleMessage.create({
const request = ExampleRequest.create({
message: 'Hello World!',
});

const data: Uint8Array = ExampleMessage.toBinary(message);
const data: Uint8Array = ExampleRequest.toBinary(request);
const headers: GrpcMetadata = {};

const { response } = await GrpcClient.unaryCall(
Expand Down
8 changes: 4 additions & 4 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GrpcClient } from '@mitch528/react-native-grpc';
import 'fast-text-encoding';
import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { GrpcClient } from '@mitch528/react-native-grpc';
import { RNGrpcTransport } from './transport';
import { ExampleMessage, ExamplesClient } from './_proto/example';
import { ExampleRequest, ExamplesClient } from './_proto/example';

export default function App() {
const [result, setResult] = useState<string>();
Expand All @@ -13,13 +13,13 @@ export default function App() {
GrpcClient.setInsecure(true);

const client = new ExamplesClient(new RNGrpcTransport());
const message = ExampleMessage.create({
const request = ExampleRequest.create({
message: 'Hello World',
});

const abort = new AbortController();

const unaryCall = client.sendExampleMessage(message, {
const unaryCall = client.sendExampleMessage(request, {
abort: abort.signal,
});

Expand Down

0 comments on commit d080c6f

Please sign in to comment.