
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
ng-to-react
Advanced tools
Migrating from 🅰️ to ⚛️ ? 👉 Use React components in Angular, and vice versa
👉 This package will be the a perfect match to migrate from Angular to React.
⭐ this repo if you like this package, it helps to motivate me :)
Jump to the sample repository for a a working sample (here on Stackblitz)
npm i ng-to-react
npm i react react-dom -S
npm i @types/react @types/react-dom -D
"jsx": "react-jsx",
(in your tsconfig.json, under the "compilerOptions" section)
node_modules/ng-to-react/src/* as included in your tsconfig.json compilation:
"include": [
"src", // you should already have this one if you had an "include" section :)
"node_modules/ng-to-react/src/*" // 👈 add this
// [...]
],
(NB: If someone has a better solution that this, please tell me... but pre-compilling & publish the source seems to fail the angular build when installing this lib)
At the root of you project, declare a file bridge.ts :
import { ReactBridge } from "ng-to-react";
// declare the bridge
export const reactBridge = new ReactBridge();
you can OPTINALLY declare there the directives that will be available in your react componetns globaly, such as, for instance:
export const reactBridge = new ReactBridge();
.addDirective('focus', (focus: boolean, _, elt) => setTimeout(() => focus && elt.focus()))
You can now use React & Angular together 🥳
Suppose you have an Angular component MyAngularComponent you would like to use in React.
In your component declaration file, just put:
import { reactBridge } from "./bridge";
// [...] MyAngularComponent declaration
// this will be usable in React:
export const MyAngular = reactBridge.toReact(MyAngularComponent, {
// declares that this component accepts children
children: true,
});
Then, you'll be able to use this in react:
import {MyAngular} from './my-angular.component';
// use the component, enjoy the types !
const Other = () => <MyAngular input={'whatever'}>;
Suppose you have a React component MyReactComponent you would like to use in Angular.
In your component declaration file, just put:
import { reactBridge } from "./bridge";
function MyReactComponent(props: {
data: string;
dataChange: (evt: string) => void;
}) {
// [...]
}
@Directive({ selector: "my-react-component" })
export class MyReactComponent_Angular extends reactBridge.toAngular(
MyReactComponent
) {
// a bit of extra work: You will have to map the properties yourself (type compatibility will be ensured by Tyepscript, though)
@Input()
data!: string;
@Output()
dataChange = new EventEmitter();
}
Then, declare MyReactComponent_Angular in your ng-module, and you'll be able to use your component in Angular :
<my-react-component [(data)]="whatever"></my-react-component>
Easy
function MyReactComp() {
const service = useService(SomeAngularService); // simple, isnt it ?
}
Angular outputs are bound to callback props in react.
Meaning that:
@Ouptut() valueChange: EventEmitter<string>;
Will be bound to a react prop:
valueChange: (evt: string) => any;
When importing an Angular component in React, if your angular component has a matching @Input() and @Output() property pairs, say a value input, and valueChange output, you will notice that ng-to-react will add a value$ property (name of the input, with a $ suffix) to the corresponding react type.
This property will be typed as something which is compatible with the useState() react hook. Meaning that, for if you have:
@Input() value: string;
@Ouptut() valueChange: EventEmitter<string>;
Then you will be able to use your component in react like that:
const value = useState("");
return <MyComonent value$={value} />;
... and the value state will be two-way bound with your react component !
(But of course, you can still use the value: string and valueChange: (e: string) => any props that ng-to-react will have generated for you, if you prefer so)
Currently not supported (todo):
FAQs
Migrating from 🅰️ to ⚛️ ? 👉 Use React components in Angular, and vice versa
The npm package ng-to-react receives a total of 7 weekly downloads. As such, ng-to-react popularity was classified as not popular.
We found that ng-to-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.