Hi Plasmic Community,
First of all, thanks for everything you have built so far! I think Plasmic and the way things are designed are a huge benefit for developers, designers and everyone in between.
Regarding my issue, I already tried consulting the docs, but could not resolve my issue.
I am trying to access data from a custom component inside Plasmic studio via context - which I am struggling to achieve.
I created a custom component “Company” and added some static data to it:
import React from 'react';
import { DataProvider } from '@plasmicapp/loader-nextjs';
export interface CompanyProps {
children?: React.ReactNode;
className?: string; // Add className to the props interface
}
const Company: React.FC<CompanyProps> = ({ className }) => { // Accept className prop
// Static company data
const companyData = {
name: 'Acme Corporation',
industry: 'Manufacturing',
description: 'A leading firm in the manufacturing of innovative products.'
};
return (
<div className={`container ${className}`}>
<DataProvider name="companyData" data={companyData}>
{/* The rest of your component UI */}
<p>Company Name: {companyData.name}</p>
<p>Industry: {companyData.industry}</p>
<p>Description: {companyData.description}</p>
</DataProvider>
</div>
);
};
export default Company;```
I registered the component and set providesData to true in my plasmic-init.ts like this:
PLASMIC.registerComponent(Company, {
name: 'Company',
providesData: true,
props: {
children: 'slot',
}
});
Custom component registration works, I can select the registered components and add them to the canvas, but when I try to access data from the components I cannot find the context in the data picker:
Using $ctx in with custom code yields this:
Am I missing something or doing something wrong?
Thanks in advance!!!
Best,
Jan
Relevant links:
- My project: Plasmic