Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
apollo-react-relay-pagination
Advanced tools
This is a helper library to write less code when using relay style pagination with apollo and react.
This library provides an abstraction for relay style pagination for apollo and react.
yarn add apollo-react-relay-pagination
or
npm install --save apollo-react-relay-pagination
This should be your preferred method of integration. Just enhance your component using relayPagination
and then use the loadMore
method from the props as shown below.
import { relayPagination } from "apollo-react-relay-pagination";
class ItemsBase extends React.Component {
render() {
...
}
// call this whenever you want to load more
// elements (e.g. from componentDidUpdate)
load (reload) {
if (!this.state.loadingMore) {
if (reload || (...check for hasNextPage...)) {
this.setState(p => ({ ...p, loadingMore: true }));
this.props.loadMore(reload, {
after: reload ?
null :
this.props.data.viewer.comments.pageInfo.endCursor
});
this.setState(p => ({ ...p, loadingMore: false }));
}
}
}
}
const ItemsWithPagination =
relayPagination(ItemsQuery, ItemsBase);
const ItemsWithData =
graphql(ItemsQuery)(ItemsWithPagination);
The library additionally provides the function mergeResults
that merges a new response containing a paginated list into a previous version of the same answer. You can use this to have more flexibility.
import { mergeResults } from "apollo-react-relay-pagination";
class ItemsBase extends React.Component {
render() {
...
}
}
export function getProps(props) {
props.loadMore = (reload) => {
let variables = ...;
if (!reload) {
variables.after = props.data.viewer.profile.groups.pageInfo.endCursor;
}
return props.data.fetchMore({
query: ItemsQuery,
variables,
updateQuery: (previousResult, { fetchMoreResult }) => {
return mergeResults(previousResult, fetchMoreResult, reload)
},
});
};
return props;
}
const ItemsWithData =
graphql(ItemsQuery, {
props: getProps,
})(ItemsWithPagination);
Returns a HOC that should be wrapped with graphql
itself and will provide a loadMore
method as property to the defined Component
.
loadMore
methodMerges two objects by overwriting all the values from previous
with the ones from current
besides the children that are named edges
, which will be merged. If reload
is true, then all edges from previous
are discarded.
FAQs
This is a helper library to write less code when using relay style pagination with apollo and react.
The npm package apollo-react-relay-pagination receives a total of 14 weekly downloads. As such, apollo-react-relay-pagination popularity was classified as not popular.
We found that apollo-react-relay-pagination 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.