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 server components example #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hyukkwonepic
Copy link

Hi team,

I was looking into this nextjs implementation example of yours and I thought it could be improved if it provides a React Server Components example of implementing a constructor.io API because one of the new paradigms in React and Next.js is using server components. So I've added a simple RSC example here. I'd appreciate it if you could review the changes.

Here are the updates included in the PR:

1. Next.js version upgrade

I've upgraded the nextjs version to the latest one (v14) to be able to use the app router, which allows the use of RSC.

Due to this upgrade, there were some changes:The new version doesn't allow the Link component to wrap the <a /> element so I removed it, and the Image component's width and height value became a number type.

2. Added RSC example

The ServerComponentsExamplePage component fetches data using ConstructorIONode from the Node.js client library. I tried to implement the fetchResultsServerSide function's behavior instead of using the function because it is designed to fit in the getServerSideProps for the original nextjs page implementation.

In the page component, userParameters data is collected according to the new nextjs 14 version. I've aimed to implement an example comparable to others, focusing on data fetching and UI rendering. If necessary, we can add a pagination here.

3. Possible bug?

In the fetchResultsServerSide function, I believe the cioNode.search.getSearchResults method's second parameter is not a position for the userParameters.

The signature says:

  getSearchResults(
    query: string,
    parameters?: SearchParameters,
    userParameters?: UserParameters,
    networkParameters?: NetworkParameters
  ): Promise<SearchResponse>;

So I passed the userParameters as a third argument. I'm not sure this is correct in version "4.5.3" of the @constructor-io/constructorio-node package as I couldn't find the documentation for the version. It would be great to confirm if this change is appropriate.

I would appreciate your review of these changes. If you have any questions or need any adjustments, please let me know!

- Set up app directory
- Implemented searching on the example page
- Added 'use client' directive to ProductCard component
@hyukkwonepic hyukkwonepic force-pushed the add-react-server-components-example branch from bda024f to 8cfba04 Compare October 31, 2024 08:10
@hyukkwonepic
Copy link
Author

Update on Oct 31:

I rebased the branch on top of the recent commits

@esezen
Copy link
Contributor

esezen commented Nov 8, 2024

Hey @hyukkwonepic , thanks a lot for your contribution!
We have been very busy and couldn't find time to review this yet but it's in our radar.

@esezen esezen requested a review from a team November 8, 2024 13:18
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

Successfully merging this pull request may close these issues.

2 participants