An open API service indexing awesome lists of open source software.

https://github.com/alloc/react-scenic

(WIP) Experimental router for React Native
https://github.com/alloc/react-scenic

react react-native

Last synced: 9 months ago
JSON representation

(WIP) Experimental router for React Native

Awesome Lists containing this project

README

          

# react-scenic

The best observable router for React. 🌋

## API

The API is under development. Expect breaking changes and undocumented features.

### Scenic

The `` component decides which scenes are mounted, which scene is focused, and which scenes have been visited.

```tsx

{children}

```

 

### ScenicRoot

The context of a `` component. It tracks the current scene as well as past scenes. Its properties can be used in a `withAuto` component (eg: to render elements conditionally).

 

### useScenic

Use the `ScenicRoot` of the nearest `` ancestor.

```ts
const scenic = useScenic()
scenic.visit('/')
```

 

### useScenicRef

Convenience hook for `useRef(null)`

Useful in the parent that renders a `` component.

```tsx
const scenicRef = useScenicRef()
const rootElement = {scenes}

useEffect(() => {
scenicRef.current.visit('/foo')
})
```

 

### useScene

Use the `Scene` of the nearest `` ancestor.

```ts
const scene = useScene()
```

Or get the `Scene` for a path, creating one if necessary:

```ts
const scene = useScene(path)
```

 

### Scene

Scenes are used to conditionally render elements based on the current path (or the history of paths) of the nearest `` component ancestor. Its properties can be observed by any `withAuto` component.

To create a `Scene`, you can call `ScenicRoot#get` or the `useScene` hook.

```ts
const scene = useScene('/')
// ..same as..
const scenic = useScenic()
const scene = scenic.get('/')
```

Both calls are idempotent, meaning they will always return the same `Scene` if you ever pass the same path multiple times.

 

### SceneMatch

Render children if a given `path` or `scene` is mounted.

```tsx
// with a path:

{children}

// or with a Scene object:

{children}

```