Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add React example to documentation #34

Open
lightstrike opened this issue Apr 3, 2018 · 3 comments
Open

Add React example to documentation #34

lightstrike opened this issue Apr 3, 2018 · 3 comments

Comments

@lightstrike
Copy link

Bibblio looks really interesting! Adding an integration example for React would be very helpful for me to evaluate this for my company.

@nicc
Copy link
Contributor

nicc commented May 1, 2018

Hi there,

firstly, my sincerest apologies for the late reply. We honestly just didn't see this issue somehow. We've made sure that won't happen again.

As for your question... we do run the related content module in a React stack for our admin dashboard. Here's a gist of how it works: https://gist.github.com/nicc/4939de77fa8e4f6cc2892d76b9d36af5
It assumes you've installed our related content module with Bower and included CSS and JS assets.
(I'm sure you know this but getInitialState, componentDidMount and render are all React lifecycle functions)

Let me know if you have any further questions!

All the best,
Nic

@claytoncollie
Copy link

Any extra movement on this issue? I am seeing React components in the readme but they are simply not working for me. I am building a site with NextJS and the component mentioed above and the ones in the readme are not pulling through any data.

It is because I am working on http://localhost:3000 and that is not a whitelisted domain?

Copy pasting the components from the exmaple above or the readme and it is printing to the DOM, but just not seeing any related items. And yes, there are plenty of related items in the content-items folder. When I view the content item browser, I see related items to a specific entry. And I am hard coding that entry to test that something will pull thru.

Any help using React and NextJS would be appreciated. Thank you!

@dushakov92
Copy link

@nicc's example is written in ES5 (May 2018).
this is what worked for me (Oct. 2021).

import {Bibblio} from 'bibblio-related-content-module'
import React, {useEffect, useState} from 'react'

export default function Recommendations({post}) {
  const [mounted, setMounted] = useState(false)

  useEffect(() => {
    setMounted(true)
  }, [])

  if (mounted) {
    Bibblio.initRelatedContent({
      targetElementId: 'my-bibblio-container',
      recommendationKey: 'your recommendation key',
      customUniqueIdentifier: 'your custom unique identifier'
    })
  }

  return (
    <div>
      <h1>Related Content</h1>
      <div id="my-bibblio-container"></div>
    </div>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants