Reputation: 1
I have a problem. I am creating a native module for React Native Windows and I might not have fully understood how the module registration works.
This is my test1.h
`#pragma once
#include "pch.h"
using namespace winrt;
REACT_MODULE(MyNativeModule);
struct MyNativeModule
{
REACT_METHOD(Add, L"add");
double Add(double a, double b) noexcept
{
double result = a + b;
return result;
}
};`
And this is the ReactPackageProvider.cpp
`#include "pch.h"
#include "ReactPackageProvider.h"
#include "NativeModules.h"
#include "test1.h"
using namespace winrt;
using namespace Microsoft::ReactNative;
namespace winrt::xxxxxxxx::implementation
{
void ReactPackageProvider::CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept
{
AddAttributedModules(packageBuilder, true);
}`
But when i call it from react i have undefined
`NativeModules
} from 'react-native';
const { MyNativeModule } = NativeModules;
MyNativeModule.add(20, 40, (result) => {
console.log(result) // 60
});`
What am I doing wrong? Thanks a lot to everyone.
Upvotes: 0
Views: 89