DEV Community

ADS-BNE
ADS-BNE

Posted on • Edited on

How do I actually get data from a CMS into my React component?

I am new to React and my immediate goal is to build React components locally and use them within my existing CMS. The end goal is to eventually go headless, but that is far down the road at this point.

Ideally I want to have a JS object on a page in the CMS that has all the variables/props I need for the React component I want to put there.

The issues I'm facing are:

  • Building React locally without having access to this data.
  • Getting the built/compiled React component to "see" this data once it's been uploaded to the CMS.

For the issue with building locally I tried using ternary operators and try/catches to set the props, eg:

const greeting = cmsComponentObj.title ? cmsComponentObj.title : 'Data not from CMS object';

But since cmsComponentObj was not defined anywhere the build failed.

I'm a bit lost as to how to achieve this. Can anyone point me in the right direction?

Top comments (0)