@joystick.js/ui

lifeycle.on_before_render()

How to use the lifecycle.on_before_render() method to do something before a component is rendered.

Before a component is rendered for mount (or re-rendered following an existing mount), if present, the on_before_render() method for the component will be called.

Example Usage

ui/pages/index/index.js

import joystick from '@joystick.js/ui';

const Index = joystick.component({
  lifecycle: {
    on_before_render: (instance = {}) => {
      // Handle the on_before_render() event.
    },
  },
  render: ({ state, when }) => {
    return `
      <div>...</div>
    `;
  },
});

export default Index;
Use Caution With State

It's important to avoid calling set_state() inside of on_before_render() to copy props or other values over to state as it can cause unwanted rendering bugs. Instead, set your default state value to a function and map the props from the instance passed to that function over to state.

API

Definition
on_before_render(component_instance: object) => undefined
Parameters
component_instance object required
The current component instance.