FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Document method to call on refs · Issue #419 · rescript-react-native/rescript-react-native · GitHub

Document method to call on refs #419

Description

Bringing this over from Discord as requested by @MoOx. I'm basically not sure if this is the right way to use refs and if the external I've defined in the following example should be exposed in the repo:

open ReactNative;
open ReactNavigation;

// TODO: add to TextInput?
external elementToObj: TextInput.element => Js.t({..}) = "%identity";

[@react.component]
let make = (~navigation: Navigation.t) => {
  open Navigation;
  let (text, onChangeText) = React.useState(() => "Home");
  let ref = React.useRef(Js.Nullable.null);

  React.useEffect0(() => {
    let intervalId =
      Js.Global.setTimeout(
        () =>
          switch (ref->React.Ref.current->Js.Nullable.toOption) {
          | Some(_ref) => _ref->elementToObj##focus()
          | None => ()
          },
        5000,
      );
    Some(() => Js.Global.clearTimeout(intervalId));
  });

  <>
    <TouchableOpacity
      onPress={_ => navigation->Navigation.navigate("PrivacyPolicy")}>
      <Text> {React.string(text)} </Text>
    </TouchableOpacity>
    <TextInput ref onChangeText={text => onChangeText(_ => text)} />
  </>;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL