
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
react-resolver
Advanced tools
Isomorphic library to lazy-load data for React components
props
.v0.13.x
For browsers that don't nativeuly support promises, use ES6 Promise.
npm install --save react-resolver
Example is based on Stargazers.js in the demo.
Suppose you want to display list of users, but that data is loaded asynchronously via an API.
Rather than having your component handle data-fetching and rendering, you can create a "container" that fetches the data and only renders when ready:
import React from "react";
import { Resolver } from "react-resolver";
class Users extends React.Component {
render() {
return (
<ul>
{this.props.users.map(user => (
<li>{user}</li>
))}
</ul>
);
}
}
Users.defaultProps = { limit: 5 };
Users.propTypes = { users: React.PropTypes.array.isRequired };
// Rather than `export default Users`, create a container:
export default Resolver.createContainer(Users, {
resolve: {
users: function(props) {
return fetch(`/api/users?limit=${props.limit}`);
}
}
});
Replace React.render
with Resolver.render
, and you're all set!
import React from "react";
import Resolver from "react-resolver";
Resolver.render(<Users />, document.getElementById("app"));
Because data has to be fetched asynchronously, React.renderToString
(and React.renderToStaticMarkup
) won't have the data in time.
Instead, replace React
with Resolver
and you'll receive a promise
that resolves with the rendered output!
import React from "react";
import Resolver from "react-resolver";
Resolver.renderToString(<Users />).then((string) => {
reply(string);
}).catch((err) {
// An error was thrown while rendering
console.error(err);
});
If you'd like to contribute to this project, all you need to do is clone this project and run:
$ npm install
$ npm test
If you have questions or issues, please open an issue!
FAQs
Async-rendering & data-fetching for universal React applications
The npm package react-resolver receives a total of 2,649 weekly downloads. As such, react-resolver popularity was classified as popular.
We found that react-resolver demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.