Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use function component.React new feature HOOKS.how to use with it? #355

Open
ongbona opened this issue Dec 12, 2019 · 0 comments
Open

Use function component.React new feature HOOKS.how to use with it? #355

ongbona opened this issue Dec 12, 2019 · 0 comments

Comments

@ongbona
Copy link

ongbona commented Dec 12, 2019

Can you give me the example of a function component?
I don't use class components.
So what can I do? If I want to use meteor subscribe
I use like that

import React, { useState } from "react";
import { View, Text } from "react-native";
import {
  Container,
  Header,
  Content,
  Form,
  Item,
  Input,
  Label,
  Button,
  Text
} from "native-base";
// meteor
import Meteor, { withTracker, MeteorListView } from "react-native-meteor";

Meteor.connect("ws://192.168.1.100:3000/websocket"); //do this only once

let f = {
  name: "Bona",
  age: 20
};
export default () => {
  const [form, setForm] = useState(f);
  function btnRegister() {
    let doc = {
      name: form.name,
      age: Number(form.age)
    };
    Meteor.call("insertCustomer", doc, (err, result) => {
      if (result) {
        console.log("inserted", result);
      } else {
        console.log("err", err);
      }
    });
  }
  return (
    <Container>
      <Header />
      <Content>
        <Form>
          <Item fixedLabel>
            <Label>Username</Label>
            <Input
              value={form.name.toString()}
              onChangeText={value => setForm({ ...form, name: value })}
            />
          </Item>
          <Item fixedLabel last>
            <Label>Age</Label>
            <Input
              keyboardType="number-pad"
              value={form.age.toLocaleString()}
              onChangeText={value => setForm({ ...form, age: value })}
            />
          </Item>
          <Item>
            <Button onPress={btnRegister}>
              <Text>Register</Text>
            </Button>
          </Item>
        </Form>
      </Content>
    </Container>
  );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant