Coder Social home page Coder Social logo

bubblydoo / angular-react Goto Github PK

View Code? Open in Web Editor NEW
29.0 5.0 8.0 2.08 MB

Use React in Angular and Angular in React, easily

Home Page: https://dev.to/bubblydoo/transitioning-from-angular-to-react-without-starting-from-scratch-j66

License: MIT License

JavaScript 3.21% TypeScript 96.79%
angular microfrontend react

angular-react's People

Contributors

hansottowirtz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

angular-react's Issues

Using angular modal service from react

Hi,

I am trying to use a modal service in a react component. But I am unable to use the useObservable hook in this scenario.
The react component is embedded in react-wrapper but that seems to work ok. The problem is that I don't seem to understand how to obtain the result of the modal window display.
Could you please provide me some guidance on this?
Thank you!

export function Confirmation() {
  const flxModalService = useInjected(FlxModalService)
  const [confirmation, setConfirmation] = useState<boolean | null>(null);

  const confirm = () => {
    const modal = flxModalService.show(
      ConfirmationModalComponent,
      {
        closeOnBackdropClick: false,
        backdropClass: 'overlay-backdrop',
      },
      {
        message: `Are you sure you want to continue?`,
        btnOkText: `Ok`,
      }
    )
    const [data, error, completed] = useObservable(modal.data$)
    if (data.confirm) {
      console.log('Confirmed')      
    }
  }

  return (
    <div style={{ border: "1px solid", padding: "5px", margin: "5px" }}>
      <p>this is React: </p>
      <button onClick={ () => confirm()}>Confirm</button>
    </div>
  );
}

Guidance on passing functions to `props` with `react-wrapper`

Hello! I am trying to get my head around how I can add callback functions to the react-wrapper component. I have the following:

<react-wrapper [component]="MuiButton" [props]="{ color: 'secondary' }">Click me!</react-wrapper>

It seems like I should be able to add something like onClick: doSomething like so:

<react-wrapper [component]="MuiButton" [props]="{ color: 'secondary', onClick: doSomething }">Click me!</react-wrapper>

But that doesn't appear to work. Some guidance would be great!

Guidence on using angular-react with next.js

Hello,

I am following the demo found in bubblydoo/next.js-angular-demo in order to document support for a design system in angular, but i am facing a couple of issues, the version of angular-react package has advanced and now AngularWrapperWithModule requires a injector so i am doing this:

suspendingLazyAngularWrapperWithPromises.tsx

import * as React from "react"
import { NgModuleRef } from "@angular/core"
import {
	AngularWrapper,
	AngularWrapperWithModule
} from "@bubblydoo/angular-react"
import { suspend } from "suspend-react"

import { AngularInjectorContext } from "./lazyAngularContextProvider"

export function SuspendingLazyAngularWrapperWithPromises({
	moduleRefPromise,
	componentPromise,
	serverFallback,
	...props
}: {
	moduleRefPromise: Promise<NgModuleRef<any> | "IS_SERVER">
	componentPromise: Promise<any>
	serverFallback: any
} & Omit<Parameters<typeof AngularWrapper>[0], "component">) {
	const injector = React.useContext(AngularInjectorContext)

	const [moduleRef, component] = suspend(
		(moduleRefPromise, componentPromise) =>
			Promise.all([moduleRefPromise, componentPromise]),
		[moduleRefPromise, componentPromise]
	)

	const [loaded, setLoaded] = React.useState(false)
	React.useEffect(() => setLoaded(true), [])

	if (!loaded || moduleRef === "IS_SERVER") return serverFallback

	return (
		<AngularWrapperWithModule
			component={component}
			moduleRef={moduleRef}
			injector={injector ?? moduleRef.injector}
			{...props}
		/>
	)
}

lazyAngularContextProvider.tsx

import * as React from "react"
import type { Injector, NgModuleRef } from "@angular/core"

export const LazyAngularModuleContext =
	React.createContext<() => Promise<NgModuleRef<any> | "IS_SERVER">>(null)

export const AngularInjectorContext = React.createContext<Injector | null>(null)

export default function LazyAngularModuleContextProvider(props: {
	children: any
	moduleRefLoader: () => Promise<NgModuleRef<any> | "IS_SERVER">
	injector?: Injector
}) {
	const moduleRefPromiseRef = React.useRef<Promise<
		NgModuleRef<any> | "IS_SERVER"
	> | null>(null)

	const moduleRefLoader = props.moduleRefLoader

	const cachedModuleRefLoader = React.useCallback(() => {
		if (moduleRefPromiseRef.current) return moduleRefPromiseRef.current
		const newModuleRefPromise = moduleRefLoader()
		moduleRefPromiseRef.current = newModuleRefPromise
		return newModuleRefPromise
	}, [moduleRefLoader])

	return (
		<LazyAngularModuleContext.Provider value={cachedModuleRefLoader}>
			<AngularInjectorContext.Provider value={props.injector ?? null}>
				{props.children}
			</AngularInjectorContext.Provider>
		</LazyAngularModuleContext.Provider>
	)
}

designSystemNameButton.tsx

	const componentLoader = React.useCallback(
		() => import("primeng/button").then((m) => m.Button),
		[]
	)
	return (
			<LazyAngularWrapper
				fallback={<h1>Loading...</h1>}
				componentLoader={componentLoader}
				inputs={{ label: "Click me!" }}
			/>
	)

_app.tsx

import "../globals.css"
import "@angular/compiler"

import configureZonejs from "../components/AngularWrapper/configureZoneJs"
import LazyAngularModuleContextProvider from "../components/AngularWrapper/lazyAngularContextProvider"
import loadAngularModule from "../components/AngularWrapper/loadAngularModule"

typeof document !== "undefined" && configureZonejs()

const moduleRefLoader = () => {
	if (typeof document === "undefined") return Promise.resolve("IS_SERVER")
	return import("primeng/button")
		.then((m) => m.ButtonModule)
		.then((m) => loadAngularModule(m))
}

export default function App({ Component, pageProps }) {
	return (
		<LazyAngularModuleContextProvider moduleRefLoader={moduleRefLoader}>
			<Component {...pageProps} />
		</LazyAngularModuleContextProvider>
	)
}

however when using the Wrapper component i get the following error:
NullInjectorError: NullInjectorError: No provider for ZoneStablePendingTask!

How should i go about using angular-react in a next.js project?

Let me know if there is anything i can do to help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.