![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
react-waypoint-decorator
Advanced tools
Decorator to apply waypoints to React components
react-waypoint is a library that allows you to run code when an element scrolls into view. This is a decorator that wraps a React component in a waypoint, and passes down an activated
prop to that component the first time it scrolls into view. It's especially handy for animating elements in as the user scrolls down the page.
npm install react-waypoint-decorator
This package has one peer dependency, React:
{
"peerDependencies": {
"react": ">=16.2.0"
}
}
This is the most basic form of a scroll trigger. This component will receive an activated
prop, which is either true
or false
depending on if the component has scrolled into view yet. By default, "scrolled into view" means that the top edge of the element is at least halfway up the page. You can fine-tune this threshold by passing an options object to the decorator.
import React, { Component } from 'react';
import waypoint from 'react-waypoint-decorator';
@waypoint()
export default class Box extends Component {
render() {
if (this.props.activated) {
return <p>You can see me!</p>;
}
return <p>You can't see me yet.</p>;
}
}
Note that this example uses the experimental decorator syntax. If you use Babel to transpile JavaScript, you can add decorator support with the decorators transform plugin.
If your setup doesn't support decorators, you can also call the decorator as a function.
import React, { Component } from 'react';
import waypoint from 'react-waypoint-decorator';
class Box extends Component {
render() {
if (this.props.activated) {
return <p>You can see me!</p>;
}
return <p>You can't see me yet.</p>;
}
}
export default waypoint()(Box);
The new component created by the decorator will wrap your component and its waypoint in a plain <div />
. This means your component will now be block-level, and generally fill the width of its container. Keep this in mind when adding waypoints, particularly if you use a grid system. If you style a component to have a percentage width, and then wrap it in a waypoint, the percentage width won't be applied, because the component is now wrapped in a full-width <div />
.
<div>
<Waypoint />
<YourComponent />
</div>
You can pass an object of options to the decorator to customize the waypoint. For example, the activatedProp
option lets you change the name of the "activated" prop passed to the component. Refer to the full list of options below.
@waypoint({
activatedProp: 'visible',
offset: 25,
})
class Box extends Component {}
Instead of passing an object to the waypoint()
decorator, you can also pass a function gets the component props as a parameter, and returns options.
@waypoint(props => ({
offset: props.offset,
}))
class Box extends Component {}
To run code when a component scrolls into view, use componentDidUpdate()
. Or, to update state in response to the scroll event, use getDerivedStateFromProps()
.
@waypoint
class Box extends Component {
componentDidUpdate(prevProps) {
if (!prevProps.activated && this.props..activated) {
// If we're here, then the component has scrolled into view for the first time
}
}
}
The decorator tracks the scroll position of the entire component. If you only want to monitor a specific chunk of a component, we've got you covered with the <Waypoint />
component.
import React, { Component } from 'react';
import { Waypoint } from 'react-waypoint-decorator';
export default class Box extends Component {
render() {
return (
<div>
<p>This part of the component isn't being monitored.</p>
<Waypoint>
{activated => (
<p>But this part is.{activated && ' And it\'s scrolled into view!'}</p>
)}
</Waypoint>
</div>
);
}
}
The <Waypoint />
component takes a render function as a child. The function has one parameter, activated
, which is true
or false
depending on if that chunk of HTML has scrolled into view yet.
waypoint(options)
Create a waypoint decorator with custom settings.
activated
.50
, which means the top edge of the component must be 50% of the way up the screen to trigger the waypoint. Higher numbers make components trigger later, while lower numbers make them trigger sooner.<div />
. To change this, pass a function to this object that takes one parameter, children
, and returns JSX.Returns a decorated React component.
<Waypoint />
React component that wraps the output of a render function in a waypoint. The render function takes these parameters:
The <Waypoint />
component takes these props:
50
, which means the top edge of the component must be 50% of the way up the screen to trigger the waypoint. Higher numbers make components trigger later, while lower numbers make them trigger sooner.<div />
. To change this, pass a function to this object that takes one parameter, children
, and returns JSX.git clone https://github.com/ueno-llc/react-waypoint-decorator
cd react-waypoint-decorator
npm install
npm test
MIT © ueno.
FAQs
Decorator to apply waypoints to React components
The npm package react-waypoint-decorator receives a total of 0 weekly downloads. As such, react-waypoint-decorator popularity was classified as not popular.
We found that react-waypoint-decorator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.