0.0.2 • Published 2 years ago

@oosawy/react-warp v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-warp

Construct Warp Tunnels to warp elements between renders in React🪐

Warning This library is still Proof of Concept, and not tested enough. Don't use this in production!

Motivation

An article is work in progress.

Install

npm i @oosawy/react-warp

Usage

  1. Add <WarpProvider /> your app to prepare the warp tunnels.
// if you use next.js, _app.tsx is good place to put WarpProvider
import type { AppProps } from 'next/app'
import { WarpProvider } from '@oosawy/react-warp'

export default function MyApp({ Component, pageProps }: AppProps) {
  return (
    <WarpProvider>
      <Component {...pageProps} />
    </WarpProvider>
  )
}
  1. Then wrap the element which you want to be warped with <Warp />. then the element will be warped to the same <Warp /> in other renders. Note: the children are only allowed to have one React element, which must have a key prop.
const IndexPage = () => {
  return (
    <div>
      <LandingLayout
        header={
          <Warp>
            <input type="text" key="search-input" />
          </Warp>
        }
      >
        <h1>The search input warps when you navigate to another page!</h1>
        <p>So the text you entered will persist even though its state is not managed.</p>
      </LandingLayout>
    </div>
  )
}

const SearchPage = () => {
  return (
    <div>
      <SearchLayout>
        <Warp>
          <input type="text" key="search-input" />
        </Warp>
      </SearchLayout>
    </div>
  )
}
0.0.2

2 years ago

0.0.1

2 years ago