Unable to add a link back to WordPress from ReactJS using WordPress Rest API for post excerpts

Viewed 35

I am using the WordPress Rest API to inject WordPress post excerpts onto a page, which is all working fine, but cant seem to identify how to add a link back to the post, such as a read more link. (I've just added a p tag to see what pulls through for now). Checking the JSON I guessed it would be {link.rendered}, but I guess not. Any pointers would be appreciated. Code segment below

import React, { Component } from 'react'

export class WordpressBlogItems extends Component {
   state = {
       isLoaded: false
   }

   render() {
       const { title, excerpt, link } = this.props.blog;
       return (
           <div className='post'>
              <h2>{title.rendered}</h2>
              <p>Test link is : {link.rendered}</p>
              <div dangerouslySetInnerHTML={{__html: excerpt.rendered}}></div>
           </div>
       )
   }
}
export default WordpressBlogItems ```
1 Answers

So it turns out Link was correct. I was displaying it incorrectly. Should be just {link} rather than {link.rendered}.

<a href={link} className="my-links">{link}</a> 
Related