Is there a way to know inside a custom component if it's being viewed on the Builder preview (editor) or on the live page?

What are you trying to accomplish
I want to know inside a custom component if it’s being viewed on the Builder preview (editor) or on the live page.
to have some prop passed to the custom component which states the scope.

Code stack you are integrating Builder with
e.g. NextJS, react

Hi @neri,

You can use Builder.isEditing to verify if the custom component is being viewed in the preview or live page.

const Component = (props) => {
  // prevent sending request on the view pages
  if (!Builder.isEditing) {
    return null;
  }
 // other code
}
Builder.registerComponent(Component , {
  name: 'React Component',
}
1 Like