myra
TypeScript icon, indicating that this package has built-in type declarations

6.0.2 • Public • Published

Myra

Myra is (another) JSX rendering library. It is small, simple and built with and for Typescript.

npm Travis codecov Language grade: JavaScript Downloads gzip size install size

NPM

Myra is a JSX rendering engine implementing a subset of React, but with some differences.

Setup

Add a reference to myra, for example by installing it with NPM:

npm install --save myra

Add a tsconfig.json to your project:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "jsxFactory": "myra.h",
    "jsxFragmentFactory": "myra.Fragment",

    /* Optional, but recommended */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true
  }
}

Mounting a component

Use myra.mount to mount a component to the DOM:

    // Mount the component to a DOM element
    myra.mount(<MyComponent />, document.body) 

Implemented hooks

Memoized components

Use myra.memo to create a component that will only render if it's props have changed. The second argument is an optional comparison function to make a custom rendering decision:

    // Mount the component to a DOM element
    const MyMemoComponent = myra.memo<IProps>(props => <p></p>) 

Special props

Some props and events has special behavior associated with them.

  • The key prop should be used to ensure that the state of child components is retained when they are changing position in a list. When used with elements, it may also prevent unnecessary re-rendering and thus increase performance. It's value must be unique amongst the items in the list.
  • The class prop value will be set to the className property of the element.
  • The ref prop can be used to populate a ref's current value (see https://reactjs.org/docs/hooks-reference.html#useref)

License

MIT

Copyright (c) 2016-2022 Jonathan Hedrén

Dependents (2)

Package Sidebar

Install

npm i myra

Weekly Downloads

68

Version

6.0.2

License

MIT

Unpacked Size

148 kB

Total Files

7

Last publish

Collaborators

  • jhdrn