Engineering

Our engineering is underpinned by principles that celebrate both the integrity of code and the ambition to innovate. This manifesto champions excellence, advocates for the adoption of cutting-edge technologies, and fosters an environment of continuous intellectual growth.

React elements

The preferred way to inject JavaScript into web apps is using [React] as custom elements using Remount. For instance, we may integrate a dynamic user profile component built with JavaScript as a custom element. Your HTML markup would look like so:

<x-user-profile json-props='{"email":"rico@gmail.com"}'></x-user-profile> We can then implement this as a React component: class UserProfile extends React.Component { state = {} componentDidMount() { // This will be called when <x-user-profile> first appears. fetch(this.props.email).then(data => { this.setState({ data }) }) } render() { const { data } = this.state // This markup will appear inside the <x-user-profile> element. if (!data) { return <span>Loading...</span> } else { return <div>Full name: {data.fullname}</div> } } } Using Remount, we can wire the UserProfile component to appear on <x-user-profile> elements. import { define } from 'remount' define({ 'x-user-profile': UserProfile }) For more information on this, see the Remount documentation: https://github.com/rstacruz/remount

Where to define remount()

It's preferred to define all your custom elements en masse. This can be kept in your main entry point (eg, app.js), or a file included from it (eg, initializers/elements.js).

import { define } from 'remount' import { UserProfile, UserTooltip, AvatarImage } from './components' define({ 'x-user-profile': UserProfile, 'x-user-tooltip': UserTooltip, 'x-avatar-image': AvatarImage })

See also

• remount - Mount React components as custom elements https://github.com/rstacruz/remount • rsjs - Reasonable Structure for JavaScript https://ricostacruz.com/rsjs/

Next: Design Playbook

Connect.

Mashup Garage, a premier software development team, specialises in crafting exceptional products for startups and enterprises. With expertise in React, Elixir/Phoenix, and Ruby on Rails, we deliver solutions that meet your unique needs. Our mission is to bring value backed by decades of technical expertise and global co-founding experience.

What do you need help with?

Build a project

Build a team

Consult

Speak to someone

Expect a guaranteed response from us in 1-2 business days.

United Kingdom

London

Islington, London

+44 738 777 3405

LDN

Philippines

Manila

3F Topy IV Building, 3 Economia Road, Bagumbayan, Quezon City, 1110

+63 917 3084089

MNL