Custom Components Integrated into Editor + React.js

Long story short it would be really cool to build custom components with React in Wix Studio.

Elements that’s pre-built by Wix that we drag and drop is actually React components that’s built by Wix to also integrate with Wix’s UI features such as controlling design of an element, adding animations and interactions etc.

But there are limited amount of elements that’s provided by Wix it’s more than enough for basic needs and even enough for most cases but it might be not enough when advanced UI is required.

It would be really cool to build custom components using React inside Wix. So this is the summary of what I’m saying but here is the model I imagine:

We will have a folder in /public directory for custom components that we will build with React just like in custom elements. And we will write our own .jsx codes here. Basically we will write React components and export them similar to what we do in custom elements. But this time we are using React to build custom components.

→ We may even have a docs for building components that will also integrate with Wix’s UI features like animations, interactions etc. So Wix can tell us to -build your components like that, to integrate components with Wix’s features.

→ Components we build with React will have an API called .props so we will be able to set it’s props or get the current props of it. This API will allow any value that React allow. Main difference here between custom elements is the value type that’s allowed.

→ We may also be able to import current pre-built components by Wix and use these components in the components we build. These pre-built components will use Wix’s CSS so we won’t need to add CSS.

→ And also we may be able to import and use React UI libraries from npm in that way we can build advanced custom components like charts. Which we can also build with custom elements from scratch, but problem is that from scratch.

→ We will be able to use React features like useState.

→ These components will also support basic APIs of Velo like .show, hide, collapse, expand, delete, restore, rendered… etc.

→ To style the elements we can use global.css file and classes inside of it. By importing it into components we build.

→ We will be able to import and use other components we built in another component we are building. (Or components from libraries/Wix)

→ This feature might also be integrated with Codux which is Wix’s product. We may create our React components in Codux and Wix can pull the components that we built in Codux.

After we build our React components we will be able to see these components with their previews in the editor panel (inside the elements panel) and drag and drop them just like pre-built other elements.

And just like other elements we will be able to control these components with Velo by the provided APIs.


Why not to use Wix Blocks or Custom Element for this?

Wix Blocks:

  • Wix Blocks already provide us pre-built components by Wix. Then point of creating custom components with React is create components that’s not available in Wix or components that’s requires advanced logic.

Note: We will also be able to create custom components in Wix Blocks just like in the editor and in that way we can even convert these custom components into a better form by adding them events, extra APIs etc. via Wix Blocks. So this feature would also available in Blocks.

Custom Element:

  • We can’t use React directly inside custom elements. (Main reason)
  • We need to setup CSS for each component. And we can’t import CSS.
  • Custom elements won’t be integrated with Wix’s features in any way.
  • Custom elements only allows string, number and boolean as data.
  • We can’t use another custom element inside of another custom element which makes it harder to build advanced UI elements. And time waste.
  • No libraries for custom elements we need to build it from scratch.

Potential benefits of this feature:

I think there is only one but very important benefit of this: creating advanced UI will be possible and we will be able to solve problems like repeater-in-repeater much more easier.

As well as we can publish React based custom components into marketplace via Wix Blocks in this way users that don’t have the knowledge of react or JS can use advanced UI elements like charts.

Current solution to all of these:

Anything above can be also done with custom elements. But harder and more time required as well as we will have more problems when creating advanced UI elements with custom elements. I already listed above why custom elements aren’t good always.

2 Likes

To add some extra notes:

  • I have tried different things to use React with custom elements to achieve similar result. But it was not possible.

  • We can create re-usable react components and save them into different .js files (or inside of a single one) and then use these components in custom elements. Which may help sometimes.

  • We can’t import CSS inside .js so external components are not possible to use even custom components are hard to build because of this, inline styling can be used however. Or we can write styles in a string export it and paste it into style tag, which works.

  • When git enabled we can setup a compiler in our local env to write actual React and babel will compile it to .js and save it to our public dir to use in custom elements. Which is something very helpful.


In the end it’s not possible to create a similar experience to what I have talked above. It would be better to let Wix give us ability at least of one of these:

  • Use React and CSS to fully design pages instead of drag and drop.

  • Use React to create custom components that’s integrated into Wix’s elements panel, like widgets in Wix Blocks.

  • Use X to create advanced UI via code (X can be one or multiple of these: react, vue, angular, html, css etc.)


About using Wix Headless instead of these: this is def possible and make sense but we will have different problems when we choose this; first of all we will need to build everything (I mean UI not backend features) and this is not what I’m talking about what I say is let us add complex things only when needed but in a better way because custom elements are not very good always and probably will also create SEO problems. Using Wix Headless all alone will make everything complex.