# @ingeneric/ngcomponent

> A clean React-like abstraction for rendering non-Angular components within an Angular app.

Latest version **6.0.4** (published 2023-07-10) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @ingeneric/ngcomponent
pnpm add @ingeneric/ngcomponent
yarn add @ingeneric/ngcomponent
bun add @ingeneric/ngcomponent
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.4 |
| Published | 2023-07-10 |
| First published | 2023-07-08 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Boris Cherny |
| Maintainers | amokrushin |
| Keywords | angular, component, react, directive, props, state, controller |

## Links

- npm: https://www.npmjs.com/package/@ingeneric/ngcomponent
- Repository: https://github.com/ingeneric/ngcomponent
- Homepage: https://github.com/ingeneric/ngcomponent#readme
- Issues: https://github.com/ingeneric/ngcomponent/issues
- npm.io page: https://npm.io/package/@ingeneric/ngcomponent

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 6.0.4 (latest) — 2023-07-10
- 6.0.3 — 2023-07-10
- 6.0.2 — 2023-07-08
- 6.0.1 — 2023-07-08
- 6.0.0 — 2023-07-08

## README

# NgComponent [![Build Status][build]](https://github.com/ingeneric/ngcomponent/actions) [![npm]](https://www.npmjs.com/package/ngcomponent) [![license]](https://opensource.org/license/apache-2-0/)

[build]: https://github.com/ingeneric/ngcomponent/actions/workflows/npm-publish.yml/badge.svg
[npm]: https://img.shields.io/npm/v/@ingeneric/ngcomponent.svg
[license]: https://img.shields.io/npm/l/@ingeneric/ngcomponent.svg

An actualized version of the [coatue-oss/ngcomponent](https://github.com/coatue-oss/ngcomponent) package.

> A clean React-like abstraction for rendering non-Angular components within an Angular app.

## Installation
``
```sh
npm i @ingeneric/ngcomponent --save
```

**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM.

## Usage

*Note: This example is in TypeScript, but it works just as well in vanilla JavaScript*

```ts
import NgComponent from 'ngcomponent'

interface Props {
  foo: number
  bar: string[]
}

interface State {}

const myComponent = {
  bindings: {
    foo: '<',
    bar: '<'
  },
  template: `
    <div></div>
  `,
  controller: class extends NgComponent<Props, State> {
    ...
  }
}
```

## Full Example

```ts
import NgComponent from 'ngcomponent'

interface Props {
  data: number[]
  type: "bar"|"line"
}

interface State {
  chart: Chart
}

const chartJSWrapper = {
  bindings: {
    data: '<',
    type: '<'
  },
  template: `<canvas></canvas>`,
  constructor(private $element: JQuery){}
  controller: class extends NgComponent<Props, State> {

    componentDidMount() {
      this.state.chart = new Chart($element.find('canvas'), {
        data: props.data,
        type: props.type
      })
    }

    render() {
      this.state.chart.data = this.props.data
      this.state.chart.type = this.props.type
      this.state.chart.update()
    }

    componentWillUnmount() {
      this.state.chart.destroy()
    }
  }
}
```

## Lifecycle Hooks

NgComponent has a React-like component lifecycle API:

- `render()` (use this to react to changes to `this.props`)
- `componentWillMount()`
- `componentDidMount()`
- `componentWillReceiveProps(props)`
- `shouldComponentUpdate(props, state)`
- `componentWillUpdate(props, state)`
- `componentDidUpdate(props, state)`
- `componentWillUnmount()`

## Running the Tests

```sh
npm test
```

## License

Apache 2.0

---
_Source: https://npm.io/package/@ingeneric/ngcomponent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
