Skip to content

Note on initialization #32

@ScreamZ

Description

@ScreamZ

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Helpful HintsInsights on selected topics

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions