How do I embed react-native-windows into an existing UWP application? #10817
-
I currently have an existing C# UWP project. I also have a few components already implemented in react native that I would like to utilize in my UWP app. How do I do this without having to replace my This is probably related to: Integration with existing uwp applications. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
It's certainly possible, but there isn't a straightforward sample that exists today. You can also open a sample request on the repo: https://github.com/microsoft/react-native-windows-samples/issues/new/choose |
Beta Was this translation helpful? Give feedback.
-
Sorry it turns out I've written it but forgot to post it that long. Here's what I did, @chrisglein ApproachThe original scenario, where we have an existing react-native application, and we would like to create a UWP app for it, we would usually use
Throughout the following steps, I’ll assume that:
What to doThe steps mentioned here will assume that we would like to have our UWP project code-base outside of the root directory of the react native project.
That helps us out by creating the necessary configuration for react native to acknowledge that there will be a windows app utilizing the react native project.That, however, generates a hello-world windows application utilizing our RN project. We don’t need that. So we can safely delete the recently-generated
Where:
This is a workaround to a bug mentioned here that can cause the Windows build of certain 3rd-party packages to fail.
We need to add
It is very important for the value given to Still in the same
We need to add
The contents of the partial void will be handled automatically later during the auto-link process.
We should add
It is essential for this step to succeed. Upon its success, few things are going to happen:
This may seem very similar to the code generated by RN, except the generated never sets the RN dispatcher in The next thing we need to do, while we’re still in the
Which was also part of
And then use it!
Don’t forget that at the code-behind of this page, you would also need to set the
Where
|
Beta Was this translation helpful? Give feedback.
Sorry it turns out I've written it but forgot to post it that long. Here's what I did, @chrisglein
@hunainhumail-purevpn FYI
Approach
The original scenario, where we have an existing react-native application, and we would like to create a UWP app for it, we would usually use
npx react-native-windows-init
, ornpx react-native-windows-init --language cs
to generate the project in C# instead of C++ (more about react-native-windows-init). This will create awindows
directory under the root directory of the react native project. We would then need to auto-link the project (more about auto-linking). This, however, could be done automatically by running the recently-created project usingnpx rea…