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

Note on initialization #32

Open
ScreamZ opened this issue Dec 2, 2020 · 1 comment
Open

Note on initialization #32

ScreamZ opened this issue Dec 2, 2020 · 1 comment
Labels
Helpful Hints Insights on selected topics

Comments

@ScreamZ
Copy link

ScreamZ commented Dec 2, 2020

Hey,

I've been using NextJS, but also the last version of Expo that doesn't directly expose component registration.
Sometimes you want full control and don't care about "DOM-like" registration.

I ended up with such pattern :

import React from "react";
import { SafeAreaView, Text } from "react-native";
import { launchApp } from "feature-u";
import features from "./features";

export default function App() {
  const [RootElement, setRootElement] = React.useState();
  const [message, setMessage] = React.useState("");

  React.useEffect(() => {
    launchApp({
      features,
      registerRootAppElm(rootAppElm) {
        setRootElement(rootAppElm);
      },
      showStatus(message, error) {
        setMessage(message ?? error.message);
      },
    });
  }, []);

  if (!message && typeof RootElement !== "undefined") {
    return RootElement;
  }

  return (
    <SafeAreaView>
      <Text>{message}</Text>
    </SafeAreaView>
  );
}

While kind of hacky, this works fine, it might help some people. I don't like the way to block UI rendering while everything is loading. I might want to hook some "Homemade" splash screen on a mobile app.

Hope this help :)
Andréas

PS: I'm also working on a typescript definition file for the library, I'll make a PR soon

@KevinAst
Copy link
Owner

KevinAst commented Dec 4, 2020

Thanks Andréas. I haven't been following Expo releases, and I am not a NextJS user.

Evidently as of SDK 18, Expo's registerRootComponent() is handled automatically. With that said, my understanding is that you can continue to use it if you prefer. I wonder if it is in danger of being fully deprecated?

Question: Can you highlight the advantage of not using Expo's registerRootComponent()?

At any rate, thanks for the example! I will keep this post open for better visibility.

@KevinAst KevinAst added the Helpful Hints Insights on selected topics label Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Helpful Hints Insights on selected topics
Projects
None yet
Development

No branches or pull requests

2 participants