Git Product home page Git Product logo

steveeeie / react-page-transition Goto Github PK

View Code? Open in Web Editor NEW
441.0 6.0 24.0 3.52 MB

A React component that makes it easy to use the page transitions from the Codedrops page transitions demo with React

Home Page: https://codesandbox.io/s/advanced-react-page-transition-demo-z8hmd

License: MIT License

TypeScript 100.00%
react page-transitions transitions animation react-transition-group react-router styled-components

react-page-transition's Introduction

License Version Size PRs Twitter Follow

React Page Transition

โš›๏ธ๐Ÿ’จ A React component that makes it easy to use the page transitions from the Codedrops Page Transitions Demo See Original.


preview
preview


Usage with react-router

1. Install Package

npm install @steveeeie/react-page-transition

or

yarn add @steveeeie/react-page-transition


2. Install Dependencies

npm install react-router react-router-dom react-transition-group styled-components

or

yarn add react-router react-router-dom react-transition-group styled-components


3. Code Example

App.js

import React from 'react';
import { BrowserRouter, Switch, Route, Link } from 'react-router-dom';
import { PageTransition } from '@steveeeie/react-page-transition';
import './styles.css';

const Links = () => (
  <>
    <Link to="/">Home</Link>
    <Link to="/about">About</Link>
  </>
);

const Home = props => <h1>Home</h1>;

const About = props => <h1>About</h1>;

export default function App() {
  return (
    <BrowserRouter>
      <Links />
      <Route
        render={({ location }) => {
          return (
            <PageTransition
              preset="moveToLeftFromRight"
              transitionKey={location.pathname}
            >
              <Switch location={location}>
                <Route exact path="/" component={Home} />
                <Route exact path="/about" component={About} />
              </Switch>
            </PageTransition>
          );
        }}
      />
    </BrowserRouter>
  );
}

Wrap your routes inside the PageTransition component and pass one of the preset names to the preset prop. View the advanced demo for the full list of presets.

You will also need to pass the current location.path to the transitionKey prop, this is so that the internal TransitionGroup can track which components are entering and exiting.


styles.css

html,
body,
#root {
  height: 100%;
}

PageTransition is styled with height: 100%. The parent containers need to be given a height for it to render correctly because of this.


Props

Prop Required Type Description
preset No String Sets the enter and exit animations *
enterAnimation No String Sets the enter animation *
exitAnimation No String Sets the exit animation *
transitionKey Yes Unique Identifier Used internally to track which components are entering and exiting.
* View the advanced demo for the full list of presets and animations.

react-page-transition's People

Contributors

dependabot[bot] avatar steveeeie avatar xeinebiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-page-transition's Issues

Package import issue

Hey, your pacakge is very cool ! trying to implementing in my project but getting stuck in while importing package from node_module

error : "export 'default' (imported as 'PageTransition') was not found in '@steveeeie/react-page-transition'

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Support for React 17

React 17 causes this warning:

findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode. Instead, add a ref directly to the element you want to reference

Disabling strict mode doesn't fix the issue.

Does this doesn't work with latest version of react or react-router-dom ?

Does this doesn't work with latest version of react or react-router-dom after doing this:

const AnimatedRoutes = () => {
  const location = useLocation();
  return (
    <PageTransition
      preset="moveToLeftFromRight"
      transitionKey={location.pathname}
    >
      <Routes location={location} key={location.pathname}>
        <Route exact path="/" element={<Home />} />
        <Route exact path="/about" element={<About />} />
        <Route exact path="/projects" element={<Projects />} />
        <Route exact path="/blogs" element={<Blog />} />
        <Route exact path="/contact" element={<Connect />} />
      </Routes>
    </PageTransition>
  );
};

it doesn't render anything?

Module not found: Can't resolve 'react-transition-group' in '*\@steveeeie\react-page-transition\dist'

Hey there,

You package seams very cool and easy to use! :)
I try to implement it in my project, but first error that I got, was that it's not types, that it doesn't have @types/@steveeie/react-page-transition module. I resolved it by making index.d.ts file and declaring the module inside.
It worked well, but on the other hand, I got this error too:
Module not found: Can't resolve 'react-transition-group' in '*\@steveeeie\react-page-transition\dist'

Is there any solution, please ? :)

Thanks in advance !

Does this work with Gastby?

Hi, I have a project which is built upon Gatsby.
I would love to use this package/module in the project for better UI UX.

Could you please tell me, a way to integrate it into the project?

Quick response is really appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.