question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Name component functions with the Slice Name

See original GitHub issue

Current state

Right now when you create a slice with prismic sm --create-slice you are asked to give a location to build the slice, as well as a PascalCase name for that slice. The CLI then creates a folder with that name, and uses it in a few other places like the Storybook story file.

It does not use it to name the React functional component that it creates, so you get essentially this:

const MySlice = ({ slice }) => (
<div>
...
</div>
)

export default MySlice;

This means that all of your Slices have functions with the same name. This makes it less intuitive to debug errors like these:

Warning: Failed prop type: The prop `slice.primary.title` is marked as required in `MySlice`, but its value is `undefined`.

Proposed solution

We can apply the same Slice name to the function so that if I give a name of HeroSection I’ll get a component like this:

const HeroSection= ({ slice }) => (
<div>
...
</div>
)

export default HeroSection;

This will make debugging easier and also give a bit more context within the file. We are already asking for a PascalCase name, so this matches the React standard for components already.

Thoughts on this? Any potential pitfalls I’m missing with this approach?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hypervillaincommented, Jun 15, 2021

The create-slice command is now part of the local builder and it does handle naming components: https://github.com/prismicio/slice-machine/blob/with-custom-types/packages/slice-machine/templates/slice/next/index.js#L4

As Alex said, thanks a lot for taking the time to read the project @ReeceM, it’s much appreciated

1reaction
a-trostcommented, Mar 30, 2021

Great call, @ReeceM! That’s exactly what I was talking about. Seems like it’s on its way. I appreciate you surfacing that!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[RFC] Dynamically update slice function name in generate template ...
I was looking through the code related to creating slices, and it appears that Mustache is already being used for the model file...
Read more >
RFC 8677 - Name-Based Service Function Forwarder (nSFF ...
Name -Based Service Function Forwarder (nSFF) Component within a Service Function Chaining (SFC) Framework (RFC 8677, November 2019.
Read more >
PHP RFC: Consistent Function Names
This RFC only proposes renaming offending function names and have aliases for old names. Old names are _not_ deprecated.
Read more >
RFC 2580: API for metadata parts of fat pointers
We now have APIs in Stable Rust to let unsafe code freely and reliably manipulate slices, accessing the separate components of a fat...
Read more >
2603-rust-symbol-name-mangling-v0 - The Rust RFC Book
Mapping Rust Language Entities to Symbol Names​​ This RFC suggests the following mapping of Rust entities to mangled names: Named functions, methods, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found