Ideally, even if in this case nothing breaks, you would use the state, actions and libraries from Frontity packages through the store, so I’d implement it in the following way:
import React, { useEffect } from 'react';
import { connect } from 'frontity';
const Comments = ({ libraries }) => (
// Just using hooks instead of classes and `componentDidMount`.
useEffect(() => {
// Here is the real change, we are using the source library
// from the store.
libraries.source.api.get({ ... });
}, []);
return ( ... );
);
// Here we are using `connect` to pass the store that
// includes `libraries` to our component.
export default connect(Comments);
With this way of using the libraries exposed by the different packages there is an attempt to ensure that even if the code structure changes, the packages that depend on those libraries are not affected because the store exposed is exactly the same.
Also, for some extensions like wp-source there is a basic structure that needs to be respected in order to ensure compatibility between packages. This happens mostly with actions and state, but sometimes libraries are also affected by this decision. This is to ensure that, for example, mars-theme can still use actions.source.fetch(...) even if the package installed is not wp-source but another one like wp-graphql-source, because fetch is a required action to any package exposing an implementation of source.
I will definitely implement it by the way you suggested & convert it to funcational component. I’m also arranging a video call with luisherranz so can better understand frontity code base.
Before starting with this, we need to figure out how to include comments inside wp-source first. We haven’t done it yet.
Most probably they are going to live in state.source.comments[post_id] and you are going to be able to do things like actions.source.fetch("comments/my-post") but as I said, we need to figure this out.
I can work on this with @David tomorrow and get back to you.
Once the support for storing comments in wp-source is implemented it’s going to be really easy to retrieve comments from WordPress.
This is the old implementation called wp-org-comments.
Don’t worry about the logic that stored the comments, all that is going to be much easier now and stored inside wp-source.
But you can take a look at the components we had for showing the comments and creating new comments. That part is going to be quite similar I think.