Passing additional Properties in SliceZone with SliceProps

Hi,

we're trying to pass additional data to the slices via the SliceZone with the sliceProps attribute. However, I"m not seeing any of the data passed in my slices.

We're passing just some test data like so:

interface Props {
  props: any;
}

export default function Resources(props: Props) {
  return (
    <Layout {...props}>
      <SliceZone
        {...props}
        resolver={resolver}
        queryType="single"
        sliceProps={props}
      />
    </Layout>
  );
}

// Fetch content from prismic
// eslint-disable-next-line react-hooks/rules-of-hooks
export const getStaticProps = useGetStaticProps({
  client: Client(),
  queryType: 'single',
  type: 'resources',
});

However, in my slice, I don't see the additional data getting passed in, just the slice data. Does it get passed in a specific attribute like data or sliceProps or ?

Thanks,

Pete

Hey Pete!

The props passed to sliceProps need to be either an object or a function.

  • Could you share with us an example of the Slice's logs to see what they're returning?
  • Which version of next-slicezone are you using?

Hi Pau,

thanks for responding.

We are using next-slicezone version 0.0.15

In the slice I'm seeing:

ResourcesTypes
{
  slice_type: 'resources_types',
  slice_label: null,
  items: [
    { image: [Object], header: [Array], url: [Object], number: 2 },
    { image: [Object], header: [Array], url: [Object], number: 2 },
    { image: [Object], header: [Array], url: [Object], number: 3 },
    { image: [Object], header: [Array], url: [Object], number: 3 },
    { image: [Object], header: [Array], url: [Object], number: 2 }
  ],
  primary: { resourcecategories: { link_type: 'Document' } }
}

Just the slice data

Pete

Hey there, can you please update to next-slicezone@0.1.2 and try again.
Before 0.1.0, adding the sliceProps property wasn’t a possibility, so this is probably why it's not working.

Let me know how it goes.

Hi Pau,

thanks, I'll give that a try and let you know.

Thanks,

Pete

Morning Pau,

I updated the next-slicezone to 0.1.2 and still can't seem to get the sliceProps data over to my slice.

If I just pass an object into sliceProps, will all slices get that object ? Does it come thru appended to the other slice data?

Thanks,

Pete

Hey there!

Yes, those props will become available in all the Slices. You can pass a random object to the sliceProps instead of the props of the function. And see if that works.

Could you show me the code snippet where you're passing the props and how you're retrieving them in the Slice component?