Skip to content

Best practices for handling nested fields and long field names? #3261

Answered by johnrom
tparvi asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure what your X and Y are supposed to represent, but let's pretend it's a restaurant. What I would generally do is create a "Shape" which a Custom Field understands, let's say your shape is:

I'm using TypeScript, though it will work fine without it. TS allows me to explain the shapes better

interface StoreHours = {
  normal: StoreHoursMap,
  holiday: StoreHoursMap
}

type StoreHoursMap = Record<number, Hours>;

interface Hours {
   times: {
      from: string,
      to: string,
  }
};

Now you have a number of different types. These can be broken up in a million different ways depending on how reusable you want the fields to be. For example:

interface TimeFieldProps {
  name: string,

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tparvi
Comment options

@johnrom
Comment options

johnrom Jun 25, 2021
Collaborator

Answer selected by tparvi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants