npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-power-reviews

v2.0.1

Published

React module for Power Reviews

Downloads

80

Readme

Module has been changed completely from prev versions.

In order to tackle using multiple components on one page we have moved most of the config into a init function that you will call in your componentDidMount(). This does also return a promise

Here is a reference guide for power review here. If you want to add any of the aditional config just pass through an object to the config prop with the key being the prop and value being whatever you want to pass through (example below).

For feedless product look here.

As of version 1.1.0 it is recommended to use your own div with a custom id name. This way you can pass whatever id you want and will future proof the module if power-reviews comes out with more components. You will need to use the correct components still however. Here is a list of the components you can use. Make sure you spell them correctly with case in mind. If not you will get a warning in the console and your component will not render.

Note: This will not break previous builds if you were using the default exported components. If you are using them just make sure to use the correct id name as well.

I recommend testing all of the Review components to figure out which one you want. If you want to edit the style Power Review recommends using a style sheet (like below in config) and targetting the classes. Here is a very nice ui to help you target the classes you want without having to inspect if you prefer to do it this way here.

import {
 PowerReviewConfig,
 } from "react-power-reviews"

// Here is an example from a project

componentDidMount() {
 PowerReviewConfig({
  	apiKey: `Your Api Key`,
	merchantGroupId: `Your merchant Group Id`,
   	merchantId: `Your merchant Id`,
	pageId: id,
	config: { style_sheet: powerReviewStyles },
	components: {
		ReviewSnippet: `myCustomSnippetId`,
		ReviewDisplay: `myCustomDisplayId`,
   	},
	review_wrapper_url: `/write-review?page_id=${id}`,
   	// this is for feedless, reference power-reviews docs
	product: {},
	init: () => {
		// if you want to edit anything do it here, everything will be loaded before this function is called
	},
 })
}

// in your render just call the components

render() {
 return (
  <div>
   <div>
    <div id="myCustomDisplayId" />
   </div>
   <div>
    <div id="myCustomSnippetId" />
   </div>
  </div>
 )
}

Gotchas

Multiple snippets on a page

Example: You have some related products on your product page and you want to show a snippet to show the star rating of those products. You cannot make a seperate component and just render in a new config.

export default RelatedProducts extends Component {
 componentDidMount(){
  // configHere
 }
 render(){
  return (
   <Fragment>
    <div id="snippet-1" />
    <div id="snippet-2" />
   </Fragment>
  )
 }
}

This will not work. It will override the prev config and render only what was configured last. Power reviews has a fix for this, but we went ahead and did most of the heavy lifting for you.

This will be using a seperate component called CategorySnippet, not the same thing as the ReviewSnippet and therefore you will not need to worry about passing in the main product-id unless you are using the CategorySnippet for that.

You will need to get a list of all your product's ids that you want to have a snippet on the page.

const ids = [`1`, `2`, `3`]

Then you will need to attach this to your config in this exact way.

//...
componentDidMount(){
 let config = { ...normalPowerReviewConfig}

 // use this exact key
 config[`categorySnippets`] = {
  // This is the base id of the div that you will use
  id: `customId`,
  snippets: ids
 }

 PowerReviewConfig(config).catch(err => console.log(err))
}

Now to render these out you will use the base id you provided and append a - with the id right after like so:

render(){
 return (
  <Fragment>
   <div id="customId-1" />
   <div id="customId-2" />
   <div id="customId-3" />
  </Fragment>
 )
}

Each of these will now render that product's snippet. You would want to have a seperate comp or some way of dynamically being able to pass in the id's though. For example:

<div id={`customId-${id}`} />

If you do not see your content being rendered then you are most likely rendering the PowerReviewConfig twice and overriding it somewhere.