App%3A%3AApp()%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enoexcept%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20MainComponentName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22NativeModuleSample%22%3C%2FSPAN%3E)%3B%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20BUNDLE%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptBundleFile(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index.windows%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptMainModuleName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20_DEBUG%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%20%20%20%20PackageProviders().Append(make%3CREACTPACKAGEPROVIDER%3E())%3B%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20Includes%20all%20modules%20in%20this%20project%3C%2FSPAN%3E%0A%20%20%20%20PackageProviders().Append(winrt%3A%3ASampleReactModule%3A%3AReactPackageProvider())%3B%0A%0A%0A%20%20%20%20InitializeComponent()%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20This%20works%20around%20a%20cpp%2Fwinrt%20bug%20with%20composable%2Faggregable%20types%20tracked%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20by%2022116519%3C%2FSPAN%3E%0A%20%20%20%20AddRef()%3B%0A%20%20%20%20m_inner.as%26lt%3B%3A%3AIUnknown%26gt%3B()-%26gt%3BRelease()%3B%0A%7D%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22using-the-module-from-javascript%22%20id%3D%22toc-hId--68718058%22%20id%3D%22toc-hId--68718057%22%20id%3D%22toc-hId-1058678036%22%20id%3D%22toc-hId-1058678036%22%20id%3D%22toc-hId-1058678036%22%3EUsing%20the%20module%20from%20JavaScript%3C%2FH3%3E%0A%3CP%3EThat's%20it!%20Now%20we%20can%20move%20to%20the%20React%20Native%20project%20to%20start%20using%20the%20module%20we%20have%20just%20built%20from%20JavaScript.%20Open%20the%20folder%20which%20contains%20your%20React%20Native%20project%20with%20your%20favorite%20web%20editor.%20For%20me%2C%20it's%20Visual%20Studio%20Code.%20For%20simplicity%2C%20I've%20implemented%20the%20component%20which%20uses%20the%20native%20module%20directly%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.js%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20my%20React%20Native%20project%2C%20so%20that%20it%20will%20be%20the%20startup%20page.%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20is%20importing%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModule%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20exposed%20by%20React%20Native%20in%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EOur%20module%20will%20be%20exposed%20through%20this%20object%2C%20by%20leveraging%20the%20name%20of%20the%20class%20we%20have%20decorated%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactModule%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20In%20our%20case%2C%20it's%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%2C%20so%20we%20can%20use%20the%20following%20code%20to%20access%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EGetDeviceModule()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3ENativeModules.SampleComponent.getDeviceModel()%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENotice%20that%20we%20can%20reference%20the%20method%20with%20the%20lowercase%20name%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%2C%20thanks%20to%20the%20parameter%20we%20have%20passed%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactMethod%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20However%2C%20by%20default%20the%20methods%20exposed%20by%20native%20modules%20are%20implemented%20in%20an%20asynchronous%20way%20using%20callbacks.%20As%20such%2C%20if%20we%20want%20to%20consume%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20we%20need%20to%20use%20the%20following%20approach%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20accepts%20a%20function%2C%20that%20is%20invoked%20once%20the%20asynchronous%20operation%20is%20completed.%20Inside%20this%20function%20we%20receive%2C%20as%20parameter%2C%20the%20result%20returned%20by%20our%20native%20method%20(in%20our%20case%2C%20the%20model%20of%20the%20device).%20In%20our%20sample%2C%20we%20store%20it%20inside%20the%20component's%20state%2C%20so%20that%20we%20can%20display%20it%20in%20the%20user%20interface%20using%20the%20JSX%20syntax%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CTEXT%3EModel%3A%20%7B%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state.model%7D%26lt%3B%3CSPAN%20class%3D%22hljs-regexp%22%3E%2FText%26gt%3B%0A%3C%2FSPAN%3E%3C%2FTEXT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EBefore%20calling%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20however%2C%20we%20need%20to%20save%20a%20reference%20to%20the%20main%20context.%20Inside%20the%20callback%2C%20in%20fact%2C%20we%20have%20moved%20to%20a%20different%20context%2C%20so%20we%20don't%20have%20access%20to%20the%20helpers%20exposed%20by%20React%20Native.%3C%2FP%3E%0A%3CP%3EBelow%20you%20can%20find%20the%20full%20definition%20of%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20React%2C%20%7BFragment%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react'%3C%2FSPAN%3E%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%0A%20%20StyleSheet%2C%0A%20%20View%2C%0A%20%20Text%2C%0A%20%20StatusBar%2C%0A%20%20Button%0A%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-class%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EApp%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eextends%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EReact%3C%2FSPAN%3E.%3CSPAN%20class%3D%22hljs-title%22%3EComponent%3C%2FSPAN%3E%20%3C%2FSPAN%3E%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econstructor%3C%2FSPAN%3E(props)%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Esuper%3C%2FSPAN%3E(props)%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state%20%3D%20%7B%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E''%3C%2FSPAN%3E%2C%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20%20getModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%20%20%7D)%0A%20%20%7D%0A%0A%20%20render()%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20(%0A%20%20%20%20%20%20%3CVIEW%20style%3D%22%7Bstyles.sectionContainer%7D%22%3E%0A%20%20%20%20%20%20%20%20%3CSTATUSBAR%20barstyle%3D%22dark-content%22%3E%3C%2FSTATUSBAR%3E%0A%20%20%20%20%20%20%20%20%3CVIEW%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBUTTON%20title%3D%22Get%20model%22%20onpress%3D%22%7Bthis.getModel%7D%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3CTEXT%3EModel%3A%20%7Bthis.state.model%7D%3C%2FTEXT%3E%0A%20%20%20%20%20%20%20%20%3C%2FBUTTON%3E%3C%2FVIEW%3E%0A%20%20%20%20%20%20%3C%2FVIEW%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%20%0A%7D%3B%0A%0A%2F%2Fstyles%20definition%0A%0Aexport%20default%20App%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIf%20you're%20familiar%20with%20React%20Native%2C%20the%20code%20should%20be%20easy%20to%20understand%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EWe%20have%20defined%20a%20function%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%2C%20which%20takes%20care%20of%20interacting%20with%20our%20native%20module.%20The%20model%20of%20the%20device%20is%20stored%20inside%20the%20component's%20state%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20provided%20by%20React%20Native.%3C%2FLI%3E%0A%3CLI%3EThe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Erender()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethods%20defines%20the%20UI%20component%2C%20using%20the%20JSX%20syntax.%20The%20UI%20is%20very%20simple%3A%0A%3CUL%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CBUTTON%3E%3C%2FBUTTON%3E%3C%2FCODE%3E%3CBUTTON%3E%2C%20which%20invokes%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20by%20leveraging%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EonPress%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eevent.%3C%2FBUTTON%3E%3C%2FLI%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CTEXT%3E%3C%2FTEXT%3E%3C%2FCODE%3E%2C%20which%20displays%20the%20value%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Emodel%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20stored%20inside%20the%20state.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22testing-the-code%22%20id%3D%22toc-hId--1876172521%22%20id%3D%22toc-hId--1876172520%22%20id%3D%22toc-hId--748776427%22%20id%3D%22toc-hId--748776427%22%20id%3D%22toc-hId--748776427%22%3ETesting%20the%20code%3C%2FH3%3E%0A%3CP%3ENow%20it's%20time%20to%20test%20the%20code!%20First%2C%20right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDeploy%3C%2FSTRONG%3E.%20Before%20doing%20it%2C%20however%2C%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConfiguration%20Manager%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edropdown%20to%20make%20sure%20you're%20targeting%20the%20right%20CPU%20architecture.%20By%20default%2C%20in%20fact%2C%20the%20solution%20will%20target%20ARM%2C%20so%20you%20will%20have%20to%20switch%20to%20x86%20or%20x64.%20If%20it's%20the%20first%20time%20you%20build%20it%2C%20it%20will%20take%20a%20while%20since%20C%2B%2B%20compilation%20isn't%20exactly%20fast%20%3D)%3C%2Fimg%3E%20Once%20it's%20done%2C%20open%20a%20command%20prompt%20on%20the%20folder%20which%20contains%20your%20React%20Native%20project%20and%20type%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eyarn%20start%3C%2FSTRONG%3E.%20This%20will%20launch%20the%20Metro%20packager%2C%20which%20will%20serve%20all%20the%20React%20Native%20components%20to%20your%20application.%20Once%20the%20dependency%20graph%20has%20been%20loaded%2C%20you%20can%20open%20the%20Start%20menu%20and%20launch%20the%20Windows%20application%20you%20have%20just%20deployed%20from%20Visual%20Studio.%20If%20you%20have%20done%20everything%20in%20the%20correct%20way%2C%20you%20will%20see%20the%20very%20simple%20UI%20we%20have%20built%20in%20our%20component.%20By%20pressing%20the%20button%20you%20will%20invoke%20the%20native%20module%20and%20you%20will%20see%20the%20model%20of%20your%20device%20being%20displayed%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F161931i3F5738A5D5FF1338%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ReactNativeApp.png%22%20title%3D%22ReactNativeApp.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22improving-the-code%22%20id%3D%22toc-hId-611340312%22%20id%3D%22toc-hId-611340313%22%20id%3D%22toc-hId-1738736406%22%20id%3D%22toc-hId-1738736406%22%20id%3D%22toc-hId-1738736406%22%3EImproving%20the%20code%3C%2FH3%3E%0A%3CP%3EIf%20you%20compare%20this%20development%20experience%20with%20the%20one%20you%20have%20when%20you%20add%20a%203rd%20party%20module%20to%20your%20project%20using%20yarn%20or%20npm%2C%20you%20realize%20that%20it's%20quite%20different.%20In%20such%20a%20case%2C%20in%20fact%2C%20you%20don't%20have%20to%20deal%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%3B%20or%20you%20don't%20need%20to%20use%20callbacks%20to%20call%20the%20various%20methods.%20Let's%20use%20again%20the%20example%20of%20the%20popular%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAsyncStorage%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emodule.%20If%20you%20want%20to%20store%20some%20data%20in%20the%20storage%2C%20you%20just%20import%20a%20reference%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EAsyncStorage%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20and%20then%20you%20call%20an%20asynchronous%20method%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetItem%3C%2FCODE%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20AsyncStorage%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'%40react-native-community%2Fasync-storage'%3C%2FSPAN%3E%3B%0A%0AstoreData%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20AsyncStorage.setItem(%3CSPAN%20class%3D%22hljs-string%22%3E'%40storage_Key'%3C%2FSPAN%3E%2C%20%3CSPAN%20class%3D%22hljs-string%22%3E'stored%20value'%3C%2FSPAN%3E)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ECan%20we%20achieve%20the%20same%20goal%20with%20the%20native%20module%20we%20have%20just%20built%3F%20The%20answer%20is%20yes!%20We%20just%20need%20to%20build%20a%20JavaScript%20wrapper%2C%20that%20will%20make%20consuming%20our%20native%20module%20more%20straightforward.%3C%2FP%3E%0A%3CP%3EIn%20Visual%20Studio%20Code%20add%20a%20new%20file%20in%20your%20React%20Native%20project%20and%20call%20it%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESampleComponent.js%3C%2FSTRONG%3E.%20First%2C%20let's%20import%20the%20same%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20we%20have%20previously%20imported%20in%20the%20main%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENow%2C%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdevelopers.google.com%2Fweb%2Ffundamentals%2Fprimers%2Fpromises%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EJavaScript%20Promises%3C%2FA%3E%2C%20we%20can%20build%20a%20wrapper%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetResult()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%20Thanks%20to%20Promises%2C%20we%20can%20enable%20an%20easier%20approach%20to%20consume%20our%20asynchronous%20API%2C%20thanks%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords.%20If%20you%20have%20some%20C%23%20background%2C%20this%20approach%20is%20similar%20to%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETaskCompletionSource%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20to%20build%20asynchronous%20operations%20that%20returns%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETask%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject-%3C%2FP%3E%0A%3CP%3EThis%20is%20how%20we%20can%20wrap%20the%20method%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eexport%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econst%3C%2FSPAN%3E%20getDeviceModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-built_in%22%3EPromise%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-function%22%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresolve%2C%20reject%3C%2FSPAN%3E)%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%2C%20error%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(error)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20reject(error)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eelse%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20resolve(result)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20returns%20a%20new%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPromise%3C%2FCODE%3E%2C%20which%20requires%20us%20to%20fulfill%20two%20objects%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CCODE%3Eresolve%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20completed%20successfully.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3Ereject%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20failed.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EInside%20the%20Promise%20we%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20in%20the%20same%20way%20we%20were%20doing%20before%20in%20the%20component.%20The%20only%20difference%20is%20that%2C%20in%20this%20case%2C%20once%20the%20callback%20is%20completed%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresult%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresolve()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20in%20case%20of%20success%3B%20otherwise%2C%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eerror%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereject()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%3C%2FP%3E%0A%3CP%3ENow%20that%20we%20have%20built%20our%20wrapper%2C%20we%20can%20simplify%20the%20component%20we%20have%20previously%20built.%20First%2C%20remove%20the%20following%20line%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThen%20replace%20it%20with%20the%20following%20one%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20*%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eas%3C%2FSPAN%3E%20SampleComponent%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'.%2FSampleComponent'%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20import%20will%20expose%20the%20functions%20we%20have%20defined%20in%20our%20wrapper%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject.%20Now%20you%20can%20change%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20simply%20with%20this%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20model%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20SampleComponent.getDeviceModel()%3B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.setState(%20%7B%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20model%7D)%3B%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAs%20you%20can%20see%2C%20thanks%20to%20Promises%20and%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords%2C%20the%20code%20is%20simpler%20to%20write%20and%20read.%20We%20just%20need%20to%20mark%20the%20function%20as%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%2C%20then%20call%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent.getDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eprefix.%20Since%20the%20asynchronous%20operation%20is%20managed%20for%20us%2C%20we%20can%20treat%20it%20like%20if%20it's%20synchronous%20and%20just%20store%20in%20a%20variable%20the%20result%2C%20which%20will%20contain%20the%20device%20model.%20Since%20we%20aren't%20using%20callbacks%2C%20we%20can%20also%20set%20the%20state%20directly%20by%20calling%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ethis.setState()%3C%2FCODE%3E.%20If%20you%20are%20a%20C%23%20developer%2C%20everything%20should%20be%20very%20familiar%2C%20since%20it's%20the%20same%20async%20and%20await%20approach%20supported%20by%20C%23.%3C%2FP%3E%0A%3CP%3EThat's%20it!%20Now%20launch%20the%20application%20again.%20In%20this%20case%20we%20didn't%20touch%20the%20native%20project%2C%20so%20if%20the%20Metro%20packager%20was%20still%20running%2C%20we%20should%20already%20be%20seeing%20the%20updated%20version.%20Of%20course%20there%20won't%20be%20any%20difference%2C%20since%20we%20didn't%20change%20the%20UI%20or%20the%20behavior%2C%20but%20the%20code%20is%20easier%20to%20read%20and%20maintain%20now.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22exporting-the-module%22%20id%3D%22toc-hId--1196114151%22%20id%3D%22toc-hId--1196114150%22%20id%3D%22toc-hId--68718057%22%20id%3D%22toc-hId--68718057%22%20id%3D%22toc-hId--68718057%22%3EExporting%20the%20module%3C%2FH3%3E%0A%3CP%3ESo%20far%2C%20we%20have%20added%20the%20native%20module%20implementation%20directly%20in%20the%20project.%20What%20if%20we%20want%20to%20create%20a%20true%20self-contained%20module%2C%20that%20we%20can%20install%20using%20yarn%20or%20npm%20like%20any%20other%203rd%20party%20module%3F%20Well%2C%20unfortunately%20the%20story%20isn't%20complete%20for%20Windows%20yet.%20By%20following%20the%20documentation%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Freact-native-windows%2Fblob%2Fmaster%2Fvnext%2Fdocs%2FNativeModulesSetup.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eavailable%20on%20GitHub%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eit's%20easy%20to%20create%20the%20skeleton%20of%20the%20module.%20We%20just%20need%20to%20create%20a%20new%20React%20Native%20module%20project%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ecreate-react-native-module%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ECLI%20tool%2C%20add%20the%20React%20Native%20for%20Windows%20package%20and%20then%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EInclude%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ewindows%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewith%20the%20Windows%20Runtime%20Component%20we%20have%20developed.%3C%2FLI%3E%0A%3CLI%3EOptionally%20include%20any%20JavaScript%20wrapper%20we%20might%20have%20created%20to%20make%20easier%20consuming%20the%20module.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EIf%20you%20already%20have%20a%20module%20with%20iOS%20and%20Android%20support%2C%20you'll%20just%20need%20instead%20to%20follow%20step%201%20and%20include%20the%20windows%20folder%20with%20the%20Windows%20Runtime%20Component%20in%20your%20existing%20project.%3C%2FP%3E%0A%3CP%3EHowever%2C%20regardless%20of%20your%20scenario%2C%20the%20current%20React%20Native%20for%20Windows%20implementation%20lacks%20an%20important%20feature%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elinking%3C%2FSTRONG%3E.%20You'll%20remember%20that%2C%20in%20the%20previous%20section%2C%20we%20had%20to%20manually%20edit%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20the%20React%20Native%20project%20to%20load%2C%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EReactPackageProvider%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%2C%20our%20Windows%20Runtime%20Component.%20On%20Android%20and%20iOS%20this%20operation%20isn't%20needed%20thanks%20to%20linking.%20You%20just%20need%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereact-native%20link%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%3A%20it%20will%20take%20care%20of%20everything%20for%20you%2C%20without%20needing%20to%20manually%20edit%20the%20Android%20and%20iOS%20projects.%20React%20Native%200.60%20has%20brought%20linking%20to%20the%20next%20level%2C%20by%20introducing%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eautomatic%20linking%3C%2FSTRONG%3E.%20You%20don't%20even%20have%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elink%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%20anymore%3B%20just%20add%20the%20package%20to%20your%20project%20and%20React%20Native%20will%20take%20of%20everything%20else%20for%20you.%20The%20React%20Native%20implementation%20for%20iOS%20and%20Android%20will%20automatically%20load%20all%20the%203rd%20party%20modules%20that%20have%20been%20added%20to%20the%20project.%20This%20feature%20isn't%20available%20on%20Windows%20yet%20and%2C%20as%20such%2C%20if%20you%20create%20an%20independent%20module%20and%20you%20publish%20it%20on%20NPM%2C%20you%20will%20still%20need%20to%20manually%20open%20the%20React%20Native%20for%20Windows%20solution%20in%20Visual%20Studio%20and%20register%20the%20module%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22publishing-the-application%22%20id%3D%22toc-hId-1291398682%22%20id%3D%22toc-hId-1291398683%22%20id%3D%22toc-hId--1876172520%22%20id%3D%22toc-hId--1876172520%22%20id%3D%22toc-hId--1876172520%22%3EPublishing%20the%20application%3C%2FH3%3E%0A%3CP%3ECompared%20to%20the%20last%20time%20I%20wrote%20about%20React%20Native%20for%20Windows%2C%20there's%20a%20big%20news!%20Now%20you%20can%20create%20a%20deployable%20version%20of%20the%20application%3A%20an%20AppX%20%2F%20MSIX%20package%20which%20is%20self-contained%20and%20that%20doesn't%20need%20the%20Metro%20packager%20to%20be%20up%20%26amp%3B%20running.%20This%20way%2C%20you%20can%20publish%20the%20application%20on%20the%20Microsoft%20Store%20or%20using%20one%20of%20the%20many%20supported%20deployment%20techniques%20(sideloading%2C%20SSCM%2C%20Intune%2C%20etc.).%20To%20achieve%20this%20goal%20just%20start%20the%20publishing%20process%2C%20like%20you%20would%20do%20with%20any%20Universal%20Windows%20Platform%20application.%20Right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%2C%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPublish%20%E2%86%92%20Create%20app%20packages%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20follow%20the%20wizard.%20Just%20make%20sure%2C%20in%20the%20package%20configuration%20step%2C%20to%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ERelease%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20configuration%20mode.%20This%20way%2C%20all%20the%20React%20Native%20resources%20will%20be%20bundled%20together%2C%20removing%20the%20requirement%20of%20having%20the%20Metro%20packager%20up%20%26amp%3B%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22wrapping-up%22%20id%3D%22toc-hId--516055781%22%20id%3D%22toc-hId--516055780%22%20id%3D%22toc-hId-611340313%22%20id%3D%22toc-hId-611340313%22%20id%3D%22toc-hId-611340313%22%3EWrapping%20up%3C%2FH3%3E%0A%3CP%3EIn%20this%20post%20we%20have%20seen%20how%20you%20can%20build%20native%20modules%20for%20React%20Native%20for%20Windows.%20This%20will%20allow%20us%20to%20build%20applications%20using%20the%20React%20stack%20but%2C%20at%20the%20same%20time%2C%20leverage%20native%20features%20provided%20by%20Windows%2C%20like%20toast%20notifications%2C%20access%20to%20Bluetooth%20APIs%2C%20file%20system%2C%20etc.%20We%20have%20also%20learned%20how%20we%20can%20distribute%20an%20application%20built%20with%20React%20Native%2C%20either%20via%20the%20Microsoft%20Store%20or%20one%20of%20the%20many%20techniques%20supported%20by%20MSIX%2C%20like%20sideloading%20or%20Microsoft%20Intune.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20the%20sample%20I've%20built%20for%20this%20post%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-UWP%2Ftree%2Fmaster%2FNativeModulesSample%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eon%20GitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20coding!%3C%2FP%3E%3C%2FREACTPACKAGEPROVIDER%3E%0AApp%3A%3AApp()%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enoexcept%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20MainComponentName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22NativeModuleSample%22%3C%2FSPAN%3E)%3B%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20BUNDLE%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptBundleFile(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index.windows%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptMainModuleName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20_DEBUG%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%20%20%20%20PackageProviders().Append(make%3CREACTPACKAGEPROVIDER%3E())%3B%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20Includes%20all%20modules%20in%20this%20project%3C%2FSPAN%3E%0A%20%20%20%20PackageProviders().Append(winrt%3A%3ASampleReactModule%3A%3AReactPackageProvider())%3B%0A%0A%0A%20%20%20%20InitializeComponent()%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20This%20works%20around%20a%20cpp%2Fwinrt%20bug%20with%20composable%2Faggregable%20types%20tracked%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20by%2022116519%3C%2FSPAN%3E%0A%20%20%20%20AddRef()%3B%0A%20%20%20%20m_inner.as%26lt%3B%3A%3AIUnknown%26gt%3B()-%26gt%3BRelease()%3B%0A%7D%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22using-the-module-from-javascript%22%20id%3D%22toc-hId--68718057%22%20id%3D%22toc-hId-1971457053%22%20id%3D%22toc-hId--1196114150%22%20id%3D%22toc-hId--1196114150%22%3EUsing%20the%20module%20from%20JavaScript%3C%2FH3%3E%0A%3CP%3EThat's%20it!%20Now%20we%20can%20move%20to%20the%20React%20Native%20project%20to%20start%20using%20the%20module%20we%20have%20just%20built%20from%20JavaScript.%20Open%20the%20folder%20which%20contains%20your%20React%20Native%20project%20with%20your%20favorite%20web%20editor.%20For%20me%2C%20it's%20Visual%20Studio%20Code.%20For%20simplicity%2C%20I've%20implemented%20the%20component%20which%20uses%20the%20native%20module%20directly%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.js%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20my%20React%20Native%20project%2C%20so%20that%20it%20will%20be%20the%20startup%20page.%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20is%20importing%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModule%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20exposed%20by%20React%20Native%20in%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EOur%20module%20will%20be%20exposed%20through%20this%20object%2C%20by%20leveraging%20the%20name%20of%20the%20class%20we%20have%20decorated%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactModule%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20In%20our%20case%2C%20it's%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%2C%20so%20we%20can%20use%20the%20following%20code%20to%20access%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EGetDeviceModule()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3ENativeModules.SampleComponent.getDeviceModel()%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENotice%20that%20we%20can%20reference%20the%20method%20with%20the%20lowercase%20name%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%2C%20thanks%20to%20the%20parameter%20we%20have%20passed%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactMethod%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20However%2C%20by%20default%20the%20methods%20exposed%20by%20native%20modules%20are%20implemented%20in%20an%20asynchronous%20way%20using%20callbacks.%20As%20such%2C%20if%20we%20want%20to%20consume%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20we%20need%20to%20use%20the%20following%20approach%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20accepts%20a%20function%2C%20that%20is%20invoked%20once%20the%20asynchronous%20operation%20is%20completed.%20Inside%20this%20function%20we%20receive%2C%20as%20parameter%2C%20the%20result%20returned%20by%20our%20native%20method%20(in%20our%20case%2C%20the%20model%20of%20the%20device).%20In%20our%20sample%2C%20we%20store%20it%20inside%20the%20component's%20state%2C%20so%20that%20we%20can%20display%20it%20in%20the%20user%20interface%20using%20the%20JSX%20syntax%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CTEXT%3EModel%3A%20%7B%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state.model%7D%26lt%3B%3CSPAN%20class%3D%22hljs-regexp%22%3E%2FText%26gt%3B%0A%3C%2FSPAN%3E%3C%2FTEXT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EBefore%20calling%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20however%2C%20we%20need%20to%20save%20a%20reference%20to%20the%20main%20context.%20Inside%20the%20callback%2C%20in%20fact%2C%20we%20have%20moved%20to%20a%20different%20context%2C%20so%20we%20don't%20have%20access%20to%20the%20helpers%20exposed%20by%20React%20Native.%3C%2FP%3E%0A%3CP%3EBelow%20you%20can%20find%20the%20full%20definition%20of%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20React%2C%20%7BFragment%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react'%3C%2FSPAN%3E%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%0A%20%20StyleSheet%2C%0A%20%20View%2C%0A%20%20Text%2C%0A%20%20StatusBar%2C%0A%20%20Button%0A%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-class%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EApp%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eextends%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EReact%3C%2FSPAN%3E.%3CSPAN%20class%3D%22hljs-title%22%3EComponent%3C%2FSPAN%3E%20%3C%2FSPAN%3E%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econstructor%3C%2FSPAN%3E(props)%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Esuper%3C%2FSPAN%3E(props)%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state%20%3D%20%7B%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E''%3C%2FSPAN%3E%2C%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20%20getModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%20%20%7D)%0A%20%20%7D%0A%0A%20%20render()%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20(%0A%20%20%20%20%20%20%3CVIEW%20style%3D%22%7Bstyles.sectionContainer%7D%22%3E%0A%20%20%20%20%20%20%20%20%3CSTATUSBAR%20barstyle%3D%22dark-content%22%3E%3C%2FSTATUSBAR%3E%0A%20%20%20%20%20%20%20%20%3CVIEW%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBUTTON%20title%3D%22Get%20model%22%20onpress%3D%22%7Bthis.getModel%7D%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3CTEXT%3EModel%3A%20%7Bthis.state.model%7D%3C%2FTEXT%3E%0A%20%20%20%20%20%20%20%20%3C%2FBUTTON%3E%3C%2FVIEW%3E%0A%20%20%20%20%20%20%3C%2FVIEW%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%20%0A%7D%3B%0A%0A%2F%2Fstyles%20definition%0A%0Aexport%20default%20App%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIf%20you're%20familiar%20with%20React%20Native%2C%20the%20code%20should%20be%20easy%20to%20understand%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EWe%20have%20defined%20a%20function%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%2C%20which%20takes%20care%20of%20interacting%20with%20our%20native%20module.%20The%20model%20of%20the%20device%20is%20stored%20inside%20the%20component's%20state%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20provided%20by%20React%20Native.%3C%2FLI%3E%0A%3CLI%3EThe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Erender()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethods%20defines%20the%20UI%20component%2C%20using%20the%20JSX%20syntax.%20The%20UI%20is%20very%20simple%3A%0A%3CUL%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CBUTTON%3E%3C%2FBUTTON%3E%3C%2FCODE%3E%3CBUTTON%3E%2C%20which%20invokes%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20by%20leveraging%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EonPress%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eevent.%3C%2FBUTTON%3E%3C%2FLI%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CTEXT%3E%3C%2FTEXT%3E%3C%2FCODE%3E%2C%20which%20displays%20the%20value%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Emodel%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20stored%20inside%20the%20state.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22testing-the-code%22%20id%3D%22toc-hId--1876172520%22%20id%3D%22toc-hId--531160889%22%20id%3D%22toc-hId-1291398683%22%20id%3D%22toc-hId-1291398683%22%3ETesting%20the%20code%3C%2FH3%3E%0A%3CP%3ENow%20it's%20time%20to%20test%20the%20code!%20First%2C%20right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDeploy%3C%2FSTRONG%3E.%20Before%20doing%20it%2C%20however%2C%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConfiguration%20Manager%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edropdown%20to%20make%20sure%20you're%20targeting%20the%20right%20CPU%20architecture.%20By%20default%2C%20in%20fact%2C%20the%20solution%20will%20target%20ARM%2C%20so%20you%20will%20have%20to%20switch%20to%20x86%20or%20x64.%20If%20it's%20the%20first%20time%20you%20build%20it%2C%20it%20will%20take%20a%20while%20since%20C%2B%2B%20compilation%20isn't%20exactly%20fast%20%3D)%3C%2Fimg%3E%20Once%20it's%20done%2C%20open%20a%20command%20prompt%20on%20the%20folder%20which%20contains%20your%20React%20Native%20project%20and%20type%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eyarn%20start%3C%2FSTRONG%3E.%20This%20will%20launch%20the%20Metro%20packager%2C%20which%20will%20serve%20all%20the%20React%20Native%20components%20to%20your%20application.%20Once%20the%20dependency%20graph%20has%20been%20loaded%2C%20you%20can%20open%20the%20Start%20menu%20and%20launch%20the%20Windows%20application%20you%20have%20just%20deployed%20from%20Visual%20Studio.%20If%20you%20have%20done%20everything%20in%20the%20correct%20way%2C%20you%20will%20see%20the%20very%20simple%20UI%20we%20have%20built%20in%20our%20component.%20By%20pressing%20the%20button%20you%20will%20invoke%20the%20native%20module%20and%20you%20will%20see%20the%20model%20of%20your%20device%20being%20displayed%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F161931i3F5738A5D5FF1338%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ReactNativeApp.png%22%20title%3D%22ReactNativeApp.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22improving-the-code%22%20id%3D%22toc-hId-611340313%22%20id%3D%22toc-hId-1956351944%22%20id%3D%22toc-hId--516055780%22%20id%3D%22toc-hId--516055780%22%3EImproving%20the%20code%3C%2FH3%3E%0A%3CP%3EIf%20you%20compare%20this%20development%20experience%20with%20the%20one%20you%20have%20when%20you%20add%20a%203rd%20party%20module%20to%20your%20project%20using%20yarn%20or%20npm%2C%20you%20realize%20that%20it's%20quite%20different.%20In%20such%20a%20case%2C%20in%20fact%2C%20you%20don't%20have%20to%20deal%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%3B%20or%20you%20don't%20need%20to%20use%20callbacks%20to%20call%20the%20various%20methods.%20Let's%20use%20again%20the%20example%20of%20the%20popular%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAsyncStorage%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emodule.%20If%20you%20want%20to%20store%20some%20data%20in%20the%20storage%2C%20you%20just%20import%20a%20reference%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EAsyncStorage%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20and%20then%20you%20call%20an%20asynchronous%20method%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetItem%3C%2FCODE%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20AsyncStorage%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'%40react-native-community%2Fasync-storage'%3C%2FSPAN%3E%3B%0A%0AstoreData%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20AsyncStorage.setItem(%3CSPAN%20class%3D%22hljs-string%22%3E'%40storage_Key'%3C%2FSPAN%3E%2C%20%3CSPAN%20class%3D%22hljs-string%22%3E'stored%20value'%3C%2FSPAN%3E)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ECan%20we%20achieve%20the%20same%20goal%20with%20the%20native%20module%20we%20have%20just%20built%3F%20The%20answer%20is%20yes!%20We%20just%20need%20to%20build%20a%20JavaScript%20wrapper%2C%20that%20will%20make%20consuming%20our%20native%20module%20more%20straightforward.%3C%2FP%3E%0A%3CP%3EIn%20Visual%20Studio%20Code%20add%20a%20new%20file%20in%20your%20React%20Native%20project%20and%20call%20it%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESampleComponent.js%3C%2FSTRONG%3E.%20First%2C%20let's%20import%20the%20same%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20we%20have%20previously%20imported%20in%20the%20main%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENow%2C%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdevelopers.google.com%2Fweb%2Ffundamentals%2Fprimers%2Fpromises%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EJavaScript%20Promises%3C%2FA%3E%2C%20we%20can%20build%20a%20wrapper%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetResult()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%20Thanks%20to%20Promises%2C%20we%20can%20enable%20an%20easier%20approach%20to%20consume%20our%20asynchronous%20API%2C%20thanks%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords.%20If%20you%20have%20some%20C%23%20background%2C%20this%20approach%20is%20similar%20to%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETaskCompletionSource%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20to%20build%20asynchronous%20operations%20that%20returns%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETask%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject-%3C%2FP%3E%0A%3CP%3EThis%20is%20how%20we%20can%20wrap%20the%20method%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eexport%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econst%3C%2FSPAN%3E%20getDeviceModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-built_in%22%3EPromise%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-function%22%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresolve%2C%20reject%3C%2FSPAN%3E)%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%2C%20error%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(error)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20reject(error)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eelse%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20resolve(result)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20returns%20a%20new%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPromise%3C%2FCODE%3E%2C%20which%20requires%20us%20to%20fulfill%20two%20objects%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CCODE%3Eresolve%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20completed%20successfully.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3Ereject%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20failed.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EInside%20the%20Promise%20we%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20in%20the%20same%20way%20we%20were%20doing%20before%20in%20the%20component.%20The%20only%20difference%20is%20that%2C%20in%20this%20case%2C%20once%20the%20callback%20is%20completed%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresult%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresolve()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20in%20case%20of%20success%3B%20otherwise%2C%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eerror%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereject()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%3C%2FP%3E%0A%3CP%3ENow%20that%20we%20have%20built%20our%20wrapper%2C%20we%20can%20simplify%20the%20component%20we%20have%20previously%20built.%20First%2C%20remove%20the%20following%20line%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThen%20replace%20it%20with%20the%20following%20one%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20*%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eas%3C%2FSPAN%3E%20SampleComponent%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'.%2FSampleComponent'%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20import%20will%20expose%20the%20functions%20we%20have%20defined%20in%20our%20wrapper%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject.%20Now%20you%20can%20change%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20simply%20with%20this%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20model%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20SampleComponent.getDeviceModel()%3B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.setState(%20%7B%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20model%7D)%3B%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAs%20you%20can%20see%2C%20thanks%20to%20Promises%20and%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords%2C%20the%20code%20is%20simpler%20to%20write%20and%20read.%20We%20just%20need%20to%20mark%20the%20function%20as%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%2C%20then%20call%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent.getDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eprefix.%20Since%20the%20asynchronous%20operation%20is%20managed%20for%20us%2C%20we%20can%20treat%20it%20like%20if%20it's%20synchronous%20and%20just%20store%20in%20a%20variable%20the%20result%2C%20which%20will%20contain%20the%20device%20model.%20Since%20we%20aren't%20using%20callbacks%2C%20we%20can%20also%20set%20the%20state%20directly%20by%20calling%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ethis.setState()%3C%2FCODE%3E.%20If%20you%20are%20a%20C%23%20developer%2C%20everything%20should%20be%20very%20familiar%2C%20since%20it's%20the%20same%20async%20and%20await%20approach%20supported%20by%20C%23.%3C%2FP%3E%0A%3CP%3EThat's%20it!%20Now%20launch%20the%20application%20again.%20In%20this%20case%20we%20didn't%20touch%20the%20native%20project%2C%20so%20if%20the%20Metro%20packager%20was%20still%20running%2C%20we%20should%20already%20be%20seeing%20the%20updated%20version.%20Of%20course%20there%20won't%20be%20any%20difference%2C%20since%20we%20didn't%20change%20the%20UI%20or%20the%20behavior%2C%20but%20the%20code%20is%20easier%20to%20read%20and%20maintain%20now.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22exporting-the-module%22%20id%3D%22toc-hId--1196114150%22%20id%3D%22toc-hId-148897481%22%20id%3D%22toc-hId-1971457053%22%20id%3D%22toc-hId-1971457053%22%3EExporting%20the%20module%3C%2FH3%3E%0A%3CP%3ESo%20far%2C%20we%20have%20added%20the%20native%20module%20implementation%20directly%20in%20the%20project.%20What%20if%20we%20want%20to%20create%20a%20true%20self-contained%20module%2C%20that%20we%20can%20install%20using%20yarn%20or%20npm%20like%20any%20other%203rd%20party%20module%3F%20Well%2C%20unfortunately%20the%20story%20isn't%20complete%20for%20Windows%20yet.%20By%20following%20the%20documentation%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Freact-native-windows%2Fblob%2Fmaster%2Fvnext%2Fdocs%2FNativeModulesSetup.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eavailable%20on%20GitHub%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eit's%20easy%20to%20create%20the%20skeleton%20of%20the%20module.%20We%20just%20need%20to%20create%20a%20new%20React%20Native%20module%20project%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ecreate-react-native-module%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ECLI%20tool%2C%20add%20the%20React%20Native%20for%20Windows%20package%20and%20then%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EInclude%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ewindows%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewith%20the%20Windows%20Runtime%20Component%20we%20have%20developed.%3C%2FLI%3E%0A%3CLI%3EOptionally%20include%20any%20JavaScript%20wrapper%20we%20might%20have%20created%20to%20make%20easier%20consuming%20the%20module.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EIf%20you%20already%20have%20a%20module%20with%20iOS%20and%20Android%20support%2C%20you'll%20just%20need%20instead%20to%20follow%20step%201%20and%20include%20the%20windows%20folder%20with%20the%20Windows%20Runtime%20Component%20in%20your%20existing%20project.%3C%2FP%3E%0A%3CP%3EHowever%2C%20regardless%20of%20your%20scenario%2C%20the%20current%20React%20Native%20for%20Windows%20implementation%20lacks%20an%20important%20feature%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elinking%3C%2FSTRONG%3E.%20You'll%20remember%20that%2C%20in%20the%20previous%20section%2C%20we%20had%20to%20manually%20edit%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20the%20React%20Native%20project%20to%20load%2C%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EReactPackageProvider%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%2C%20our%20Windows%20Runtime%20Component.%20On%20Android%20and%20iOS%20this%20operation%20isn't%20needed%20thanks%20to%20linking.%20You%20just%20need%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereact-native%20link%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%3A%20it%20will%20take%20care%20of%20everything%20for%20you%2C%20without%20needing%20to%20manually%20edit%20the%20Android%20and%20iOS%20projects.%20React%20Native%200.60%20has%20brought%20linking%20to%20the%20next%20level%2C%20by%20introducing%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eautomatic%20linking%3C%2FSTRONG%3E.%20You%20don't%20even%20have%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elink%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%20anymore%3B%20just%20add%20the%20package%20to%20your%20project%20and%20React%20Native%20will%20take%20of%20everything%20else%20for%20you.%20The%20React%20Native%20implementation%20for%20iOS%20and%20Android%20will%20automatically%20load%20all%20the%203rd%20party%20modules%20that%20have%20been%20added%20to%20the%20project.%20This%20feature%20isn't%20available%20on%20Windows%20yet%20and%2C%20as%20such%2C%20if%20you%20create%20an%20independent%20module%20and%20you%20publish%20it%20on%20NPM%2C%20you%20will%20still%20need%20to%20manually%20open%20the%20React%20Native%20for%20Windows%20solution%20in%20Visual%20Studio%20and%20register%20the%20module%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22publishing-the-application%22%20id%3D%22toc-hId-1291398683%22%20id%3D%22toc-hId--1658556982%22%20id%3D%22toc-hId--531160889%22%20id%3D%22toc-hId--531160889%22%3EPublishing%20the%20application%3C%2FH3%3E%0A%3CP%3ECompared%20to%20the%20last%20time%20I%20wrote%20about%20React%20Native%20for%20Windows%2C%20there's%20a%20big%20news!%20Now%20you%20can%20create%20a%20deployable%20version%20of%20the%20application%3A%20an%20AppX%20%2F%20MSIX%20package%20which%20is%20self-contained%20and%20that%20doesn't%20need%20the%20Metro%20packager%20to%20be%20up%20%26amp%3B%20running.%20This%20way%2C%20you%20can%20publish%20the%20application%20on%20the%20Microsoft%20Store%20or%20using%20one%20of%20the%20many%20supported%20deployment%20techniques%20(sideloading%2C%20SSCM%2C%20Intune%2C%20etc.).%20To%20achieve%20this%20goal%20just%20start%20the%20publishing%20process%2C%20like%20you%20would%20do%20with%20any%20Universal%20Windows%20Platform%20application.%20Right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%2C%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPublish%20%E2%86%92%20Create%20app%20packages%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20follow%20the%20wizard.%20Just%20make%20sure%2C%20in%20the%20package%20configuration%20step%2C%20to%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ERelease%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20configuration%20mode.%20This%20way%2C%20all%20the%20React%20Native%20resources%20will%20be%20bundled%20together%2C%20removing%20the%20requirement%20of%20having%20the%20Metro%20packager%20up%20%26amp%3B%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22wrapping-up%22%20id%3D%22toc-hId--516055780%22%20id%3D%22toc-hId-828955851%22%20id%3D%22toc-hId-1956351944%22%20id%3D%22toc-hId-1956351944%22%3EWrapping%20up%3C%2FH3%3E%0A%3CP%3EIn%20this%20post%20we%20have%20seen%20how%20you%20can%20build%20native%20modules%20for%20React%20Native%20for%20Windows.%20This%20will%20allow%20us%20to%20build%20applications%20using%20the%20React%20stack%20but%2C%20at%20the%20same%20time%2C%20leverage%20native%20features%20provided%20by%20Windows%2C%20like%20toast%20notifications%2C%20access%20to%20Bluetooth%20APIs%2C%20file%20system%2C%20etc.%20We%20have%20also%20learned%20how%20we%20can%20distribute%20an%20application%20built%20with%20React%20Native%2C%20either%20via%20the%20Microsoft%20Store%20or%20one%20of%20the%20many%20techniques%20supported%20by%20MSIX%2C%20like%20sideloading%20or%20Microsoft%20Intune.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20the%20sample%20I've%20built%20for%20this%20post%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-UWP%2Ftree%2Fmaster%2FNativeModulesSample%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eon%20GitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20coding!%3C%2FP%3E%3C%2FREACTPACKAGEPROVIDER%3E%0AApp%3A%3AApp()%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enoexcept%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20MainComponentName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22NativeModuleSample%22%3C%2FSPAN%3E)%3B%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20BUNDLE%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptBundleFile(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index.windows%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptMainModuleName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20_DEBUG%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%20%20%20%20PackageProviders().Append(make%3CREACTPACKAGEPROVIDER%3E())%3B%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20Includes%20all%20modules%20in%20this%20project%3C%2FSPAN%3E%0A%20%20%20%20PackageProviders().Append(winrt%3A%3ASampleReactModule%3A%3AReactPackageProvider())%3B%0A%0A%0A%20%20%20%20InitializeComponent()%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20This%20works%20around%20a%20cpp%2Fwinrt%20bug%20with%20composable%2Faggregable%20types%20tracked%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20by%2022116519%3C%2FSPAN%3E%0A%20%20%20%20AddRef()%3B%0A%20%20%20%20m_inner.as%26lt%3B%3A%3AIUnknown%26gt%3B()-%26gt%3BRelease()%3B%0A%7D%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22using-the-module-from-javascript%22%20id%3D%22toc-hId--68718057%22%20id%3D%22toc-hId--978498612%22%20id%3D%22toc-hId-148897481%22%3EUsing%20the%20module%20from%20JavaScript%3C%2FH3%3E%0A%3CP%3EThat's%20it!%20Now%20we%20can%20move%20to%20the%20React%20Native%20project%20to%20start%20using%20the%20module%20we%20have%20just%20built%20from%20JavaScript.%20Open%20the%20folder%20which%20contains%20your%20React%20Native%20project%20with%20your%20favorite%20web%20editor.%20For%20me%2C%20it's%20Visual%20Studio%20Code.%20For%20simplicity%2C%20I've%20implemented%20the%20component%20which%20uses%20the%20native%20module%20directly%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.js%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20my%20React%20Native%20project%2C%20so%20that%20it%20will%20be%20the%20startup%20page.%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20is%20importing%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModule%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20exposed%20by%20React%20Native%20in%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EOur%20module%20will%20be%20exposed%20through%20this%20object%2C%20by%20leveraging%20the%20name%20of%20the%20class%20we%20have%20decorated%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactModule%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20In%20our%20case%2C%20it's%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%2C%20so%20we%20can%20use%20the%20following%20code%20to%20access%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EGetDeviceModule()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3ENativeModules.SampleComponent.getDeviceModel()%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENotice%20that%20we%20can%20reference%20the%20method%20with%20the%20lowercase%20name%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%2C%20thanks%20to%20the%20parameter%20we%20have%20passed%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactMethod%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20However%2C%20by%20default%20the%20methods%20exposed%20by%20native%20modules%20are%20implemented%20in%20an%20asynchronous%20way%20using%20callbacks.%20As%20such%2C%20if%20we%20want%20to%20consume%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20we%20need%20to%20use%20the%20following%20approach%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20accepts%20a%20function%2C%20that%20is%20invoked%20once%20the%20asynchronous%20operation%20is%20completed.%20Inside%20this%20function%20we%20receive%2C%20as%20parameter%2C%20the%20result%20returned%20by%20our%20native%20method%20(in%20our%20case%2C%20the%20model%20of%20the%20device).%20In%20our%20sample%2C%20we%20store%20it%20inside%20the%20component's%20state%2C%20so%20that%20we%20can%20display%20it%20in%20the%20user%20interface%20using%20the%20JSX%20syntax%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CTEXT%3EModel%3A%20%7B%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state.model%7D%26lt%3B%3CSPAN%20class%3D%22hljs-regexp%22%3E%2FText%26gt%3B%0A%3C%2FSPAN%3E%3C%2FTEXT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EBefore%20calling%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20however%2C%20we%20need%20to%20save%20a%20reference%20to%20the%20main%20context.%20Inside%20the%20callback%2C%20in%20fact%2C%20we%20have%20moved%20to%20a%20different%20context%2C%20so%20we%20don't%20have%20access%20to%20the%20helpers%20exposed%20by%20React%20Native.%3C%2FP%3E%0A%3CP%3EBelow%20you%20can%20find%20the%20full%20definition%20of%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20React%2C%20%7BFragment%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react'%3C%2FSPAN%3E%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%0A%20%20StyleSheet%2C%0A%20%20View%2C%0A%20%20Text%2C%0A%20%20StatusBar%2C%0A%20%20Button%0A%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-class%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EApp%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eextends%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EReact%3C%2FSPAN%3E.%3CSPAN%20class%3D%22hljs-title%22%3EComponent%3C%2FSPAN%3E%20%3C%2FSPAN%3E%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econstructor%3C%2FSPAN%3E(props)%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Esuper%3C%2FSPAN%3E(props)%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state%20%3D%20%7B%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E''%3C%2FSPAN%3E%2C%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20%20getModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%20%20%7D)%0A%20%20%7D%0A%0A%20%20render()%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20(%0A%20%20%20%20%20%20%3CVIEW%20style%3D%22%7Bstyles.sectionContainer%7D%22%3E%0A%20%20%20%20%20%20%20%20%3CSTATUSBAR%20barstyle%3D%22dark-content%22%3E%3C%2FSTATUSBAR%3E%0A%20%20%20%20%20%20%20%20%3CVIEW%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBUTTON%20title%3D%22Get%20model%22%20onpress%3D%22%7Bthis.getModel%7D%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3CTEXT%3EModel%3A%20%7Bthis.state.model%7D%3C%2FTEXT%3E%0A%20%20%20%20%20%20%20%20%3C%2FBUTTON%3E%3C%2FVIEW%3E%0A%20%20%20%20%20%20%3C%2FVIEW%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%20%0A%7D%3B%0A%0A%2F%2Fstyles%20definition%0A%0Aexport%20default%20App%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIf%20you're%20familiar%20with%20React%20Native%2C%20the%20code%20should%20be%20easy%20to%20understand%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EWe%20have%20defined%20a%20function%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%2C%20which%20takes%20care%20of%20interacting%20with%20our%20native%20module.%20The%20model%20of%20the%20device%20is%20stored%20inside%20the%20component's%20state%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20provided%20by%20React%20Native.%3C%2FLI%3E%0A%3CLI%3EThe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Erender()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethods%20defines%20the%20UI%20component%2C%20using%20the%20JSX%20syntax.%20The%20UI%20is%20very%20simple%3A%0A%3CUL%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CBUTTON%3E%3C%2FBUTTON%3E%3C%2FCODE%3E%3CBUTTON%3E%2C%20which%20invokes%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20by%20leveraging%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EonPress%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eevent.%3C%2FBUTTON%3E%3C%2FLI%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CTEXT%3E%3C%2FTEXT%3E%3C%2FCODE%3E%2C%20which%20displays%20the%20value%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Emodel%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20stored%20inside%20the%20state.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22testing-the-code%22%20id%3D%22toc-hId--1876172520%22%20id%3D%22toc-hId-1509014221%22%20id%3D%22toc-hId--1658556982%22%3ETesting%20the%20code%3C%2FH3%3E%0A%3CP%3ENow%20it's%20time%20to%20test%20the%20code!%20First%2C%20right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDeploy%3C%2FSTRONG%3E.%20Before%20doing%20it%2C%20however%2C%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConfiguration%20Manager%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edropdown%20to%20make%20sure%20you're%20targeting%20the%20right%20CPU%20architecture.%20By%20default%2C%20in%20fact%2C%20the%20solution%20will%20target%20ARM%2C%20so%20you%20will%20have%20to%20switch%20to%20x86%20or%20x64.%20If%20it's%20the%20first%20time%20you%20build%20it%2C%20it%20will%20take%20a%20while%20since%20C%2B%2B%20compilation%20isn't%20exactly%20fast%20%3D)%3C%2Fimg%3E%20Once%20it's%20done%2C%20open%20a%20command%20prompt%20on%20the%20folder%20which%20contains%20your%20React%20Native%20project%20and%20type%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eyarn%20start%3C%2FSTRONG%3E.%20This%20will%20launch%20the%20Metro%20packager%2C%20which%20will%20serve%20all%20the%20React%20Native%20components%20to%20your%20application.%20Once%20the%20dependency%20graph%20has%20been%20loaded%2C%20you%20can%20open%20the%20Start%20menu%20and%20launch%20the%20Windows%20application%20you%20have%20just%20deployed%20from%20Visual%20Studio.%20If%20you%20have%20done%20everything%20in%20the%20correct%20way%2C%20you%20will%20see%20the%20very%20simple%20UI%20we%20have%20built%20in%20our%20component.%20By%20pressing%20the%20button%20you%20will%20invoke%20the%20native%20module%20and%20you%20will%20see%20the%20model%20of%20your%20device%20being%20displayed%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F161931i3F5738A5D5FF1338%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ReactNativeApp.png%22%20title%3D%22ReactNativeApp.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22improving-the-code%22%20id%3D%22toc-hId-611340313%22%20id%3D%22toc-hId--298440242%22%20id%3D%22toc-hId-828955851%22%3EImproving%20the%20code%3C%2FH3%3E%0A%3CP%3EIf%20you%20compare%20this%20development%20experience%20with%20the%20one%20you%20have%20when%20you%20add%20a%203rd%20party%20module%20to%20your%20project%20using%20yarn%20or%20npm%2C%20you%20realize%20that%20it's%20quite%20different.%20In%20such%20a%20case%2C%20in%20fact%2C%20you%20don't%20have%20to%20deal%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%3B%20or%20you%20don't%20need%20to%20use%20callbacks%20to%20call%20the%20various%20methods.%20Let's%20use%20again%20the%20example%20of%20the%20popular%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAsyncStorage%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emodule.%20If%20you%20want%20to%20store%20some%20data%20in%20the%20storage%2C%20you%20just%20import%20a%20reference%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EAsyncStorage%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20and%20then%20you%20call%20an%20asynchronous%20method%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetItem%3C%2FCODE%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20AsyncStorage%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'%40react-native-community%2Fasync-storage'%3C%2FSPAN%3E%3B%0A%0AstoreData%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20AsyncStorage.setItem(%3CSPAN%20class%3D%22hljs-string%22%3E'%40storage_Key'%3C%2FSPAN%3E%2C%20%3CSPAN%20class%3D%22hljs-string%22%3E'stored%20value'%3C%2FSPAN%3E)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ECan%20we%20achieve%20the%20same%20goal%20with%20the%20native%20module%20we%20have%20just%20built%3F%20The%20answer%20is%20yes!%20We%20just%20need%20to%20build%20a%20JavaScript%20wrapper%2C%20that%20will%20make%20consuming%20our%20native%20module%20more%20straightforward.%3C%2FP%3E%0A%3CP%3EIn%20Visual%20Studio%20Code%20add%20a%20new%20file%20in%20your%20React%20Native%20project%20and%20call%20it%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESampleComponent.js%3C%2FSTRONG%3E.%20First%2C%20let's%20import%20the%20same%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20we%20have%20previously%20imported%20in%20the%20main%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENow%2C%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdevelopers.google.com%2Fweb%2Ffundamentals%2Fprimers%2Fpromises%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EJavaScript%20Promises%3C%2FA%3E%2C%20we%20can%20build%20a%20wrapper%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetResult()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%20Thanks%20to%20Promises%2C%20we%20can%20enable%20an%20easier%20approach%20to%20consume%20our%20asynchronous%20API%2C%20thanks%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords.%20If%20you%20have%20some%20C%23%20background%2C%20this%20approach%20is%20similar%20to%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETaskCompletionSource%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20to%20build%20asynchronous%20operations%20that%20returns%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETask%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject-%3C%2FP%3E%0A%3CP%3EThis%20is%20how%20we%20can%20wrap%20the%20method%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eexport%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econst%3C%2FSPAN%3E%20getDeviceModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-built_in%22%3EPromise%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-function%22%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresolve%2C%20reject%3C%2FSPAN%3E)%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%2C%20error%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(error)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20reject(error)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eelse%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20resolve(result)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20returns%20a%20new%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPromise%3C%2FCODE%3E%2C%20which%20requires%20us%20to%20fulfill%20two%20objects%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CCODE%3Eresolve%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20completed%20successfully.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3Ereject%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20failed.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EInside%20the%20Promise%20we%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20in%20the%20same%20way%20we%20were%20doing%20before%20in%20the%20component.%20The%20only%20difference%20is%20that%2C%20in%20this%20case%2C%20once%20the%20callback%20is%20completed%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresult%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresolve()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20in%20case%20of%20success%3B%20otherwise%2C%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eerror%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereject()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%3C%2FP%3E%0A%3CP%3ENow%20that%20we%20have%20built%20our%20wrapper%2C%20we%20can%20simplify%20the%20component%20we%20have%20previously%20built.%20First%2C%20remove%20the%20following%20line%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThen%20replace%20it%20with%20the%20following%20one%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20*%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eas%3C%2FSPAN%3E%20SampleComponent%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'.%2FSampleComponent'%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20import%20will%20expose%20the%20functions%20we%20have%20defined%20in%20our%20wrapper%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject.%20Now%20you%20can%20change%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20simply%20with%20this%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20model%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20SampleComponent.getDeviceModel()%3B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.setState(%20%7B%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20model%7D)%3B%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAs%20you%20can%20see%2C%20thanks%20to%20Promises%20and%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords%2C%20the%20code%20is%20simpler%20to%20write%20and%20read.%20We%20just%20need%20to%20mark%20the%20function%20as%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%2C%20then%20call%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent.getDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eprefix.%20Since%20the%20asynchronous%20operation%20is%20managed%20for%20us%2C%20we%20can%20treat%20it%20like%20if%20it's%20synchronous%20and%20just%20store%20in%20a%20variable%20the%20result%2C%20which%20will%20contain%20the%20device%20model.%20Since%20we%20aren't%20using%20callbacks%2C%20we%20can%20also%20set%20the%20state%20directly%20by%20calling%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ethis.setState()%3C%2FCODE%3E.%20If%20you%20are%20a%20C%23%20developer%2C%20everything%20should%20be%20very%20familiar%2C%20since%20it's%20the%20same%20async%20and%20await%20approach%20supported%20by%20C%23.%3C%2FP%3E%0A%3CP%3EThat's%20it!%20Now%20launch%20the%20application%20again.%20In%20this%20case%20we%20didn't%20touch%20the%20native%20project%2C%20so%20if%20the%20Metro%20packager%20was%20still%20running%2C%20we%20should%20already%20be%20seeing%20the%20updated%20version.%20Of%20course%20there%20won't%20be%20any%20difference%2C%20since%20we%20didn't%20change%20the%20UI%20or%20the%20behavior%2C%20but%20the%20code%20is%20easier%20to%20read%20and%20maintain%20now.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22exporting-the-module%22%20id%3D%22toc-hId--1196114150%22%20id%3D%22toc-hId--2105894705%22%20id%3D%22toc-hId--978498612%22%3EExporting%20the%20module%3C%2FH3%3E%0A%3CP%3ESo%20far%2C%20we%20have%20added%20the%20native%20module%20implementation%20directly%20in%20the%20project.%20What%20if%20we%20want%20to%20create%20a%20true%20self-contained%20module%2C%20that%20we%20can%20install%20using%20yarn%20or%20npm%20like%20any%20other%203rd%20party%20module%3F%20Well%2C%20unfortunately%20the%20story%20isn't%20complete%20for%20Windows%20yet.%20By%20following%20the%20documentation%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Freact-native-windows%2Fblob%2Fmaster%2Fvnext%2Fdocs%2FNativeModulesSetup.md%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eavailable%20on%20GitHub%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eit's%20easy%20to%20create%20the%20skeleton%20of%20the%20module.%20We%20just%20need%20to%20create%20a%20new%20React%20Native%20module%20project%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ecreate-react-native-module%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ECLI%20tool%2C%20add%20the%20React%20Native%20for%20Windows%20package%20and%20then%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EInclude%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ewindows%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewith%20the%20Windows%20Runtime%20Component%20we%20have%20developed.%3C%2FLI%3E%0A%3CLI%3EOptionally%20include%20any%20JavaScript%20wrapper%20we%20might%20have%20created%20to%20make%20easier%20consuming%20the%20module.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EIf%20you%20already%20have%20a%20module%20with%20iOS%20and%20Android%20support%2C%20you'll%20just%20need%20instead%20to%20follow%20step%201%20and%20include%20the%20windows%20folder%20with%20the%20Windows%20Runtime%20Component%20in%20your%20existing%20project.%3C%2FP%3E%0A%3CP%3EHowever%2C%20regardless%20of%20your%20scenario%2C%20the%20current%20React%20Native%20for%20Windows%20implementation%20lacks%20an%20important%20feature%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elinking%3C%2FSTRONG%3E.%20You'll%20remember%20that%2C%20in%20the%20previous%20section%2C%20we%20had%20to%20manually%20edit%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20the%20React%20Native%20project%20to%20load%2C%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EReactPackageProvider%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%2C%20our%20Windows%20Runtime%20Component.%20On%20Android%20and%20iOS%20this%20operation%20isn't%20needed%20thanks%20to%20linking.%20You%20just%20need%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereact-native%20link%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%3A%20it%20will%20take%20care%20of%20everything%20for%20you%2C%20without%20needing%20to%20manually%20edit%20the%20Android%20and%20iOS%20projects.%20React%20Native%200.60%20has%20brought%20linking%20to%20the%20next%20level%2C%20by%20introducing%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eautomatic%20linking%3C%2FSTRONG%3E.%20You%20don't%20even%20have%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elink%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%20anymore%3B%20just%20add%20the%20package%20to%20your%20project%20and%20React%20Native%20will%20take%20of%20everything%20else%20for%20you.%20The%20React%20Native%20implementation%20for%20iOS%20and%20Android%20will%20automatically%20load%20all%20the%203rd%20party%20modules%20that%20have%20been%20added%20to%20the%20project.%20This%20feature%20isn't%20available%20on%20Windows%20yet%20and%2C%20as%20such%2C%20if%20you%20create%20an%20independent%20module%20and%20you%20publish%20it%20on%20NPM%2C%20you%20will%20still%20need%20to%20manually%20open%20the%20React%20Native%20for%20Windows%20solution%20in%20Visual%20Studio%20and%20register%20the%20module%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20important%20information%20to%20highlight%20is%20the%20language%20choice%20for%20your%20module.%20C%2B%2B%20has%20a%20performance%20advantage%20over%20C%2B%2B%2C%20since%20it%20doesn't%20need%20to%20pull%20in%20the%20whole%20CLR%20in%20the%20React%20Native%20project.%20As%20such%2C%20especially%20if%20you're%20planning%20to%20share%20your%20module%20with%20the%20community%2C%20you%20should%20seriously%20consider%20to%20use%20C%2B%2B.%20If%2C%20instead%2C%20you're%20aiming%20to%20use%20your%20module%20only%20in%20your%20project%20and%20you%20have%20verified%20that%20the%20performance%20trade%20off%20doesn't%20heavily%20affect%20your%20application%2C%20it's%20fine%20to%20keep%20using%20C%23.%3C%2FP%3E%0A%3CH3%20id%3D%22publishing-the-application%22%20id%3D%22toc-hId-1291398683%22%20id%3D%22toc-hId-381618128%22%20id%3D%22toc-hId-1509014221%22%3EPublishing%20the%20application%3C%2FH3%3E%0A%3CP%3ECompared%20to%20the%20last%20time%20I%20wrote%20about%20React%20Native%20for%20Windows%2C%20there's%20a%20big%20news!%20Now%20you%20can%20create%20a%20deployable%20version%20of%20the%20application%3A%20an%20AppX%20%2F%20MSIX%20package%20which%20is%20self-contained%20and%20that%20doesn't%20need%20the%20Metro%20packager%20to%20be%20up%20%26amp%3B%20running.%20This%20way%2C%20you%20can%20publish%20the%20application%20on%20the%20Microsoft%20Store%20or%20using%20one%20of%20the%20many%20supported%20deployment%20techniques%20(sideloading%2C%20SSCM%2C%20Intune%2C%20etc.).%20To%20achieve%20this%20goal%20just%20start%20the%20publishing%20process%2C%20like%20you%20would%20do%20with%20any%20Universal%20Windows%20Platform%20application.%20Right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%2C%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPublish%20%E2%86%92%20Create%20app%20packages%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20follow%20the%20wizard.%20Just%20make%20sure%2C%20in%20the%20package%20configuration%20step%2C%20to%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ERelease%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20configuration%20mode.%20This%20way%2C%20all%20the%20React%20Native%20resources%20will%20be%20bundled%20together%2C%20removing%20the%20requirement%20of%20having%20the%20Metro%20packager%20up%20%26amp%3B%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22wrapping-up%22%20id%3D%22toc-hId--516055780%22%20id%3D%22toc-hId--727674394%22%20id%3D%22toc-hId--298440242%22%3EWrapping%20up%3C%2FH3%3E%0A%3CP%3EIn%20this%20post%20we%20have%20seen%20how%20you%20can%20build%20native%20modules%20for%20React%20Native%20for%20Windows.%20This%20will%20allow%20us%20to%20build%20applications%20using%20the%20React%20stack%20but%2C%20at%20the%20same%20time%2C%20leverage%20native%20features%20provided%20by%20Windows%2C%20like%20toast%20notifications%2C%20access%20to%20Bluetooth%20APIs%2C%20file%20system%2C%20etc.%20We%20have%20also%20learned%20how%20we%20can%20distribute%20an%20application%20built%20with%20React%20Native%2C%20either%20via%20the%20Microsoft%20Store%20or%20one%20of%20the%20many%20techniques%20supported%20by%20MSIX%2C%20like%20sideloading%20or%20Microsoft%20Intune.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20the%20sample%20I've%20built%20for%20this%20post%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FWindows-AppConsult-Samples-UWP%2Ftree%2Fmaster%2FNativeModulesSample%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eon%20GitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20coding!%3C%2FP%3E%3C%2FREACTPACKAGEPROVIDER%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1067893%22%20slang%3D%22en-US%22%3EBuilding%20a%20React%20Native%20module%20for%20Windows%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1067893%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EUpdate%20on%202nd%20January%202020%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20latest%20version%20of%20React%20Native%20for%20Windows%20has%20changed%20the%20namespace%20in%20which%20the%26nbsp%3B%3CSTRONG%3EIReactPackageProvider%26nbsp%3B%3C%2FSTRONG%3Einterface%20has%20been%20implemented.%20The%20previous%20one%20was%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EMicrosoft.ReactNative.Bridge%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ewhile%20the%20new%20one%20is%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EMicrosoft.ReactNative%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20snippets%20in%20the%20post%20have%20been%20updated%20to%20reflect%20this%20change.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EReact%20Native%20offers%20a%20wide%20range%20of%20modules%20to%20extend%20the%20core%20functionalities%20of%20the%20platform%2C%20developed%20either%20by%20the%20community%20or%20by%20the%20React%20team%20himself.%20These%20modules%20range%20from%20UI%20controls%2C%20helpers%20and%20services.%20Some%20of%20them%20are%20%22generic%22%20and%20they%20perform%20tasks%20which%20don't%20require%20access%20to%20any%20specific%20platform%20feature.%20For%20example%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-Redux%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20a%20very%20popular%20state%20management%20library%20used%20in%20React%20applications%20but%20since%2C%20by%20default%2C%20everything%20is%20stored%20in%20memory%2C%20it%20basically%20runs%20everywhere.%20In%20fact%2C%20the%20same%20library%20can%20be%20used%20either%20with%20web%20applications%20(using%20React)%20or%20native%20applications%20(using%20React%20Native).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20there%20are%20many%20scenarios%20in%20the%20native%20development%20space%20where%20the%20only%20way%20to%20achieve%20a%20task%20is%20by%20interacting%20with%20the%20native%20APIs%20offered%20by%20the%20platform.%20Saving%20a%20file%20in%20the%20local%20storage%3B%20getting%20information%20about%20the%20device%3B%20accessing%20to%20the%20GPS%20are%20just%20a%20few%20examples.%20In%20this%20case%2C%20the%20module%20can't%20be%20generic%2C%20because%20each%20platform%20has%20its%20own%20way%20to%20access%20to%20native%20features.%20This%20is%20why%20React%20Native%20supports%20the%20concept%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Enative%20modules%3C%2FSTRONG%3E%3A%20a%20module%20that%20is%20leveraged%20in%20the%20main%20application%20through%20JavaScript%20but%20that%2C%20under%20the%20hood%2C%20invokes%20a%20native%20component%20specific%20for%20the%20platform%20where%20the%20application%20is%20running.%20Being%20native%2C%20each%20component%20isn't%20built%20in%20JavaScript%2C%20but%20using%20the%20native%20language%20used%20by%20the%20platform.%20For%20example%2C%20take%20a%20look%20at%20the%20popular%20module%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-AsyncStorage%2C%20which%20can%20be%20used%20to%20read%20and%20write%20files%20in%20the%20local%20storage.%20As%20you%20can%20see%2C%20we%20have%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eios%3C%2FSTRONG%3E%2C%20which%20contains%20a%20XCode%20project%3B%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eandroid%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder%2C%20instead%2C%20contains%20some%20Java%20files.%20Both%20projects%20simply%20expose%20the%20same%20features%2C%20but%20implemented%20using%20the%20specific%20language%20and%20APIs%20from%20iOS%20and%20Android.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20some%20experience%20with%20Xamarin%20and%20Xamarin%20Forms%2C%20this%20approach%20will%20be%20familiar.%20It's%20the%20same%20exact%20concept%2C%20in%20fact%2C%20behind%20Xamarin%20Plugins%3A%20the%20entry%20point%20is%20a%20C%23%20wrapper%20which%2C%20under%20the%20hood%2C%20calls%20Swift%2C%20Java%20or%20UWP%20code%20based%20on%20the%20platform%20where%20the%20application%20is%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20blog%20post%20we're%20going%20to%20learn%20how%20we%20can%20build%20such%20a%20native%20module%20with%20Windows%20support%2C%20so%20that%20we%20can%20access%20to%20native%20Windows%20APIs%20when%20our%20React%20Native%20application%20is%20running%20on%20Windows.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22create-a-react-native-for-windows-project%22%20id%3D%22toc-hId-1058678036%22%20id%3D%22toc-hId--2105894705%22%3ECreate%20a%20React%20Native%20for%20Windows%20project%3C%2FH3%3E%0A%3CP%3EAs%20first%20step%2C%20let's%20create%20a%20React%20Native%20project%20with%20Windows%20support.%20I%20won't%20explain%20all%20the%20steps%2C%20since%20they%20are%20very%20well%20documented%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-on%20the%20official%20GitHub%20repository.%20Additionally%2C%20I%20already%20introduced%20React%20Native%20and%20the%20recently%20added%20Windows%20support%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-in%20another%20article.%3C%2FP%3E%0A%3CP%3EOnce%20you%20have%20completed%20all%20the%20steps%2C%20open%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ewindows%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efolder%20inside%20the%20project%20and%20double%20click%20on%20the%20Visual%20Studio%20solution.%20As%20we%20have%20learned%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-in%20the%20previous%20article%2C%20the%20solution%20contains%20a%20single%20application%20which%20is%20the%20host%20for%20our%20React%20Native%20content.%20In%20a%20regular%20scenario%20you%20won't%20need%20to%20touch%20the%20code%20here%2C%20since%20the%20whole%20development%20will%20happen%20in%20the%20JavaScript%20world.%20However%2C%20in%20our%20case%20we%20have%20to%20make%20an%20exception%2C%20since%20we%20need%20to%20interact%20with%20native%20Windows%20APIs%20to%20build%20our%20module.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22create-the-module-with-a-windows-runtime-component%22%20id%3D%22toc-hId--748776427%22%20id%3D%22toc-hId-381618128%22%3ECreate%20the%20module%20with%20a%20Windows%20Runtime%20Component%3C%2FH3%3E%0A%3CP%3ELet's%20start%20by%20adding%20a%20new%20project%20to%20the%20solution%2C%20which%20type%20is%20Windows%20Runtime%20Component.%20The%20component%20will%20give%20us%20access%20to%20all%20the%20Universal%20Windows%20Platform%20APIs.%20Additionally%2C%20being%20a%20WinRT%20component%2C%20it%20can%20be%20consumed%20regardless%20of%20the%20language%20used%20to%20build%20the%20main%20application.%20As%20a%20consequence%2C%20you're%20free%20to%20create%20a%20C%23%20or%20C%2B%2B%20component%2C%20based%20on%20the%20language%20you're%20most%20familiar%20with.%20We'll%20be%20able%20to%20leverage%20it%20from%20the%20main%20React%20Native%20host%20(which%20is%20built%20in%20C%2B%2B)%20regardless.%3C%2FP%3E%0A%3CP%3EIn%20my%20case%2C%20C%23%20is%20my%20favorite%20language%2C%20so%20I've%20chosen%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EWindows%20Runtime%20Component%20(C%23)%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Etemplate.%20If%20you%20want%20to%20use%20C%2B%2B%2C%20instead%2C%20you%20need%20to%20choose%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EWindows%20Runtime%20Component%20(C%2B%2B%2FWinRT)%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Etemplate.%20If%20you%20don't%20see%20it%2C%20you%20can%20install%20it%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-this%20extension.%20Pay%20attention%20to%20not%20use%20the%20C%2B%2B%2FCX%20template%2C%20because%20this%20approach%20to%20build%20C%2B%2B%20components%20for%20the%20Universal%20Windows%20Platform%20has%20been%20deprecated.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22WindowsRuntimeComponent.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F161930i6DA560231901BF1A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22WindowsRuntimeComponent.png%22%20alt%3D%22WindowsRuntimeComponent.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20the%20project%20has%20been%20created%2C%20you%20need%20to%20reference%20a%20couple%20of%20projects%20which%20are%20already%20included%20as%20part%20of%20the%20React%20Native%20for%20Windows%20solution.%20Right%20click%20on%20the%20project%20you%20have%20just%20created%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAdd%20%E2%86%92%20Reference%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EFrom%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EProjects%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%2C%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMicrosoft.ReactNative%3C%2FSTRONG%3E.%20This%20is%20the%20core%20React%20Native%20implementation%20for%20Windows.%3C%2FLI%3E%0A%3CLI%3EFrom%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EShared%20Projects%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%2C%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMicrosoft.ReactNative.SharedManaged%3C%2FSTRONG%3E.%20This%20project%20will%20give%20us%20access%20to%20C%23%20helpers%20that%20will%20make%20easy%20to%20build%20a%20native%20module.%20If%20you're%20using%20C%2B%2B%2C%20the%20project%20to%20reference%20is%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMicrosoft.ReactNative.Cxx%3C%2FSTRONG%3E.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThese%20projects%20are%20very%20important%20because%20they%20define%20many%20attributes%20which%20will%20allow%20you%20to%20export%20the%20native%20code%20to%20JavaScript.%20This%20way%2C%20the%20developers%20who%20are%20going%20to%20use%20your%20module%20in%20their%20React%20Native%20projects%20don't%20need%20to%20know%20anything%20about%20C%2B%2B%2C%20C%23%20or%20Windows%2010%20APIs.%20They%20just%20need%20to%20use%20standard%20and%20plain%20JavaScript%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBefore%20starting%20to%20write%20some%20code%2C%20expand%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EReferences%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esection%20of%20the%20project%2C%20select%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMicrosoft.ReactNative%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Elibrary%2C%20right%20click%20on%20it%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EProperties%3C%2FSTRONG%3E.%20Set%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ECopy%20Local%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Efalse%3C%2FSTRONG%3E%2C%20to%20make%20sure%20that%20there%20are%20no%20conflicts%20with%20the%20main%20application.%3C%2FP%3E%0A%3CP%3ENow%20we%20can%20start%20building%20our%20module.%20We're%20going%20to%20create%20a%20simple%20one%20to%20expose%20the%20information%20about%20the%20model%20of%20the%20device%20where%20the%20application%20is%20running.%20Let's%20start%20by%20renaming%20the%20default%20class%20included%20in%20the%20project%20with%20a%20more%20meaningful%20name%2C%20like%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESampleComponent%3C%2FSTRONG%3E.%20This%20should%20trigger%20the%20renaming%20also%20of%20the%20class%20declared%20inside%20the%20code.%3C%2FP%3E%0A%3CP%3ENow%20we%20just%20need%20to%20define%20one%20or%20more%20methods%2C%20that%20will%20be%20exposed%20to%20the%20React%20Native%20application.%20In%20our%20case%2C%20we're%20going%20to%20define%20a%20single%20method%20that%20will%20return%20the%20current%20device%20name%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EEasClientDeviceInformation%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20included%20in%20the%20Universal%20Windows%20Platform%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20Windows.Security.ExchangeActiveSyncProvisioning%3B%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Enamespace%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3ESampleReactModule%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3ESampleComponent%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EGetDeviceModel%3C%2FSPAN%3E()%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20EasClientDeviceInformation%20info%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20EasClientDeviceInformation()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20info.SystemProductName%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20next%20step%20is%20to%20leverage%20the%20attributes%20provided%20by%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EMicrosoft.ReactNative%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Elibrary%20to%20export%20the%20class%20and%20the%20method%20we%20have%20created%20to%20React%20Native.%20In%20our%20scenario%20we're%20going%20to%20use%20two%20of%20the%20many%20available%20ones%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CCODE%3E%5BReactModule%5D%3C%2FCODE%3E%2C%20which%20we're%20using%20to%20decorate%20the%20whole%20class.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3E%5BReactMethod%5D%3C%2FCODE%3E%2C%20which%20we're%20using%20to%20decorate%20every%20single%20method%20we%20want%20to%20expose.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThis%20is%20the%20final%20look%20of%20our%20class%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20Microsoft.ReactNative.Managed%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20Windows.Security.ExchangeActiveSyncProvisioning%3B%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Enamespace%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3ESampleReactModule%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%5B%3CSPAN%20class%3D%22hljs-meta%22%3EReactModule%3C%2FSPAN%3E%5D%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3ESampleComponent%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%5B%3CSPAN%20class%3D%22hljs-meta%22%3EReactMethod(%3CSPAN%20class%3D%22hljs-meta-string%22%3E%22getDeviceModel%22%3C%2FSPAN%3E)%3C%2FSPAN%3E%5D%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Estring%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EGetDeviceModel%3C%2FSPAN%3E()%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20EasClientDeviceInformation%20info%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20EasClientDeviceInformation()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20info.SystemProductName%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENotice%20that%20we%20have%20passed%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20as%20parameter%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EReactMethod%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20This%20is%20how%20we%20define%20the%20name%20of%20the%20method%20that%20will%20be%20available%20through%20JavaScript%20to%20the%20React%20Native%20project.%3C%2FP%3E%0A%3CP%3EThere%20are%20many%20other%20attributes%2C%20which%20can%20be%20used%20to%20expose%20additional%20stuff%20to%20the%20React%20Native%20application%2C%20like%20properties%20or%20event%20handlers.%20They%20are%20all%20documented%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-here.%3C%2FP%3E%0A%3CP%3EThe%20next%20thing%20we%20need%20is%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EReactPackageProvider%3C%2FSTRONG%3E%2C%20which%20is%20a%20special%20object%20that%20will%20allow%20the%20React%20Native%20project%20to%20load%20all%20the%20modules%20exposed%20by%20our%20library.%20By%20default%2C%20in%20fact%2C%20a%20React%20Native%20application%20loads%20only%20the%20built-in%20modules.%20Right%20click%20on%20the%20project%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAdd%20%E2%86%92%20Class%3C%2FSTRONG%3E.%20Name%20it%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EReactPackageProvider%3C%2FSTRONG%3E.%20The%20class%20is%20very%20simple%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-csharp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20Microsoft.ReactNative%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20Microsoft.ReactNative.Managed%3B%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Enamespace%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3ESampleReactModule%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Esealed%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EReactPackageProvider%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-title%22%3EIReactPackageProvider%3C%2FSPAN%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Epublic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evoid%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3ECreatePackage%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3EIReactPackageBuilder%20packageBuilder%3C%2FSPAN%3E)%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20packageBuilder.AddAttributedModules()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIt%20just%20needs%20to%20implement%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EIReactPackageProvider%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Einterface%2C%20which%20will%20require%20you%20to%20implement%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ECreatePackage()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%20Inside%20it%20we%20leverage%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EpackageBuilder%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20and%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EAddAttributedModules()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20to%20load%20all%20the%20modules%20we%20have%20decorated%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactModule%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute%20inside%20our%20project.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22register-the-module-in-the-react-native-application%22%20id%3D%22toc-hId-1738736406%22%20id%3D%22toc-hId--727674394%22%3ERegister%20the%20module%20in%20the%20React%20Native%20application%3C%2FH3%3E%0A%3CP%3EAs%20already%20mentioned%2C%20by%20default%20React%20Native%20for%20Windows%20registers%20only%20the%20modules%20which%20are%20included%20in%20the%20main%20project.%20If%20we%20would%20have%20created%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESampleComponent%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20inside%20the%20main%20React%20Native%20project%2C%20we%20wouldn't%20have%20needed%20any%20additional%20step.%20However%2C%20in%20our%20case%20we%20are%20using%20a%20separate%20Windows%20Runtime%20Component%2C%20which%20allows%20us%20to%20leverage%20a%20different%20language%20(C%23)%2C%20so%20we%20need%20an%20extra%20step%20to%20register%20the%20library%20in%20the%20main%20application.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20right%20click%20on%20the%20React%20Native%20for%20Windows%20project%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAdd%20%E2%86%92%20Reference%3C%2FSTRONG%3E.%20Select%20from%20the%20list%20the%20name%20of%20the%20Windows%20Runtime%20Component%20you%20have%20just%20created%20(in%20my%20sample%2C%20it's%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESampleReactModule%3C%2FSTRONG%3E)%20and%20press%20Ok.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExpand%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.xaml%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Enode%20in%20the%20main%20React%20Native%20project%20and%20double%20click%20on%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%20Inside%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EApp%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Econstructor%20you%20will%20find%20the%20following%20entry%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-cpp%20hljs%22%3EPackageProviders().Append(make%3CREACTPACKAGEPROVIDER%3E())%3B%0A%3C%2FREACTPACKAGEPROVIDER%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20is%20the%20code%20which%20loads%20all%20the%20modules%20that%20are%20included%20in%20the%20main%20project.%20Let's%20add%20below%20another%20registration%20for%20our%20new%20library%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-cpp%20hljs%22%3EPackageProviders().Append(winrt%3A%3ASampleReactModule%3A%3AReactPackageProvider())%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CCODE%3ESampleReactModule%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20the%20name%20of%20the%20Windows%20Runtime%20Component%20we%20have%20previously%20created%2C%20thus%20it's%20the%20namespace%20that%20contains%20our%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EReactPackageProvider%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eimplementation.%20To%20make%20this%20code%20compiling%20we%20need%20also%20to%20include%20the%20header%20file%20of%20our%20module%20at%20the%20top%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-cpp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Einclude%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-meta-string%22%3E%22winrt%2FSampleReactModule.h%22%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20is%20how%20the%20whole%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20should%20look%20like%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-cpp%20hljs%22%3E%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Einclude%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-meta-string%22%3E%22pch.h%22%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Einclude%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-meta-string%22%3E%22App.h%22%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Einclude%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-meta-string%22%3E%22ReactPackageProvider.h%22%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Einclude%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-meta-string%22%3E%22winrt%2FSampleReactModule.h%22%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enamespace%3C%2FSPAN%3E%20winrt%3A%3ANativeModuleSample%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enamespace%3C%2FSPAN%3E%20winrt%3A%3ANativeModuleSample%3A%3Aimplementation%3B%0A%0A%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%2F%20%3CSUMMARY%3E%3C%2FSUMMARY%3E%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%2F%20Initializes%20the%20singleton%20application%20object.%20%20This%20is%20the%20first%20line%20of%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%2F%20authored%20code%20executed%2C%20and%20as%20such%20is%20the%20logical%20equivalent%20of%20main()%20or%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%2F%20WinMain().%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%2F%20%3C%2FSPAN%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%0AApp%3A%3AApp()%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enoexcept%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20MainComponentName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22NativeModuleSample%22%3C%2FSPAN%3E)%3B%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20BUNDLE%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptBundleFile(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index.windows%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20JavaScriptMainModuleName(%3CSPAN%20class%3D%22hljs-string%22%3EL%22index%22%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseWebDebugger(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%20%20%20%20InstanceSettings().UseLiveReload(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eif%3C%2FSPAN%3E%20_DEBUG%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Etrue%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eelse%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%20%20%20%20InstanceSettings().EnableDeveloperMenu(%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E)%3B%0A%3CSPAN%20class%3D%22hljs-meta%22%3E%23%3CSPAN%20class%3D%22hljs-meta-keyword%22%3Eendif%3C%2FSPAN%3E%3C%2FSPAN%3E%0A%0A%20%20%20%20PackageProviders().Append(make%3CREACTPACKAGEPROVIDER%3E())%3B%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20Includes%20all%20modules%20in%20this%20project%3C%2FSPAN%3E%0A%20%20%20%20PackageProviders().Append(winrt%3A%3ASampleReactModule%3A%3AReactPackageProvider())%3B%0A%0A%0A%20%20%20%20InitializeComponent()%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20This%20works%20around%20a%20cpp%2Fwinrt%20bug%20with%20composable%2Faggregable%20types%20tracked%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-comment%22%3E%2F%2F%20by%2022116519%3C%2FSPAN%3E%0A%20%20%20%20AddRef()%3B%0A%20%20%20%20m_inner.as%26lt%3B%3A%3AIUnknown%26gt%3B()-%26gt%3BRelease()%3B%0A%7D%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22using-the-module-from-javascript%22%20id%3D%22toc-hId--68718057%22%20id%3D%22toc-hId-1759838439%22%3EUsing%20the%20module%20from%20JavaScript%3C%2FH3%3E%0A%3CP%3EThat's%20it!%20Now%20we%20can%20move%20to%20the%20React%20Native%20project%20to%20start%20using%20the%20module%20we%20have%20just%20built%20from%20JavaScript.%20Open%20the%20folder%20which%20contains%20your%20React%20Native%20project%20with%20your%20favorite%20web%20editor.%20For%20me%2C%20it's%20Visual%20Studio%20Code.%20For%20simplicity%2C%20I've%20implemented%20the%20component%20which%20uses%20the%20native%20module%20directly%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.js%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20my%20React%20Native%20project%2C%20so%20that%20it%20will%20be%20the%20startup%20page.%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20is%20importing%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModule%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20exposed%20by%20React%20Native%20in%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EOur%20module%20will%20be%20exposed%20through%20this%20object%2C%20by%20leveraging%20the%20name%20of%20the%20class%20we%20have%20decorated%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactModule%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20In%20our%20case%2C%20it's%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%2C%20so%20we%20can%20use%20the%20following%20code%20to%20access%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EGetDeviceModule()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3ENativeModules.SampleComponent.getDeviceModel()%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENotice%20that%20we%20can%20reference%20the%20method%20with%20the%20lowercase%20name%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%2C%20thanks%20to%20the%20parameter%20we%20have%20passed%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%5BReactMethod%5D%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eattribute.%20However%2C%20by%20default%20the%20methods%20exposed%20by%20native%20modules%20are%20implemented%20in%20an%20asynchronous%20way%20using%20callbacks.%20As%20such%2C%20if%20we%20want%20to%20consume%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20we%20need%20to%20use%20the%20following%20approach%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20accepts%20a%20function%2C%20that%20is%20invoked%20once%20the%20asynchronous%20operation%20is%20completed.%20Inside%20this%20function%20we%20receive%2C%20as%20parameter%2C%20the%20result%20returned%20by%20our%20native%20method%20(in%20our%20case%2C%20the%20model%20of%20the%20device).%20In%20our%20sample%2C%20we%20store%20it%20inside%20the%20component's%20state%2C%20so%20that%20we%20can%20display%20it%20in%20the%20user%20interface%20using%20the%20JSX%20syntax%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CTEXT%3EModel%3A%20%7B%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state.model%7D%26lt%3B%3CSPAN%20class%3D%22hljs-regexp%22%3E%2FText%26gt%3B%0A%3C%2FSPAN%3E%3C%2FTEXT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EBefore%20calling%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20however%2C%20we%20need%20to%20save%20a%20reference%20to%20the%20main%20context.%20Inside%20the%20callback%2C%20in%20fact%2C%20we%20have%20moved%20to%20a%20different%20context%2C%20so%20we%20don't%20have%20access%20to%20the%20helpers%20exposed%20by%20React%20Native.%3C%2FP%3E%0A%3CP%3EBelow%20you%20can%20find%20the%20full%20definition%20of%20our%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20React%2C%20%7BFragment%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react'%3C%2FSPAN%3E%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%0A%20%20StyleSheet%2C%0A%20%20View%2C%0A%20%20Text%2C%0A%20%20StatusBar%2C%0A%20%20Button%0A%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-class%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eclass%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EApp%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eextends%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EReact%3C%2FSPAN%3E.%3CSPAN%20class%3D%22hljs-title%22%3EComponent%3C%2FSPAN%3E%20%3C%2FSPAN%3E%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econstructor%3C%2FSPAN%3E(props)%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Esuper%3C%2FSPAN%3E(props)%3B%0A%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.state%20%3D%20%7B%0A%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E''%3C%2FSPAN%3E%2C%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20%20getModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20current%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E%3B%0A%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20current.setState(%7B%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20result%7D)%3B%0A%20%20%20%20%7D)%0A%20%20%7D%0A%0A%20%20render()%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20(%0A%20%20%20%20%20%20%3CVIEW%20style%3D%22%7Bstyles.sectionContainer%7D%22%3E%0A%20%20%20%20%20%20%20%20%3CSTATUSBAR%20barstyle%3D%22dark-content%22%3E%3C%2FSTATUSBAR%3E%0A%20%20%20%20%20%20%20%20%3CVIEW%3E%0A%20%20%20%20%20%20%20%20%20%20%3CBUTTON%20title%3D%22Get%20model%22%20onpress%3D%22%7Bthis.getModel%7D%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3CTEXT%3EModel%3A%20%7Bthis.state.model%7D%3C%2FTEXT%3E%0A%20%20%20%20%20%20%20%20%3C%2FBUTTON%3E%3C%2FVIEW%3E%0A%20%20%20%20%20%20%3C%2FVIEW%3E%0A%20%20%20%20)%3B%0A%20%20%7D%0A%20%0A%7D%3B%0A%0A%2F%2Fstyles%20definition%0A%0Aexport%20default%20App%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIf%20you're%20familiar%20with%20React%20Native%2C%20the%20code%20should%20be%20easy%20to%20understand%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EWe%20have%20defined%20a%20function%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%2C%20which%20takes%20care%20of%20interacting%20with%20our%20native%20module.%20The%20model%20of%20the%20device%20is%20stored%20inside%20the%20component's%20state%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetState()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20provided%20by%20React%20Native.%3C%2FLI%3E%0A%3CLI%3EThe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Erender()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethods%20defines%20the%20UI%20component%2C%20using%20the%20JSX%20syntax.%20The%20UI%20is%20very%20simple%3A%0A%3CUL%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CBUTTON%3E%3C%2FBUTTON%3E%3C%2FCODE%3E%3CBUTTON%3E%2C%20which%20invokes%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20by%20leveraging%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EonPress%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eevent.%3C%2FBUTTON%3E%3C%2FLI%3E%0A%3CLI%3EWe%20have%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3E%3CTEXT%3E%3C%2FTEXT%3E%3C%2FCODE%3E%2C%20which%20displays%20the%20value%20of%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Emodel%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eproperty%20stored%20inside%20the%20state.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22testing-the-code%22%20id%3D%22toc-hId--1876172520%22%20id%3D%22toc-hId--47616024%22%3ETesting%20the%20code%3C%2FH3%3E%0A%3CP%3ENow%20it's%20time%20to%20test%20the%20code!%20First%2C%20right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%20and%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDeploy%3C%2FSTRONG%3E.%20Before%20doing%20it%2C%20however%2C%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConfiguration%20Manager%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edropdown%20to%20make%20sure%20you're%20targeting%20the%20right%20CPU%20architecture.%20By%20default%2C%20in%20fact%2C%20the%20solution%20will%20target%20ARM%2C%20so%20you%20will%20have%20to%20switch%20to%20x86%20or%20x64.%20If%20it's%20the%20first%20time%20you%20build%20it%2C%20it%20will%20take%20a%20while%20since%20C%2B%2B%20compilation%20isn't%20exactly%20fast%20%3D)%3C%2Fimg%3E%20Once%20it's%20done%2C%20open%20a%20command%20prompt%20on%20the%20folder%20which%20contains%20your%20React%20Native%20project%20and%20type%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eyarn%20start%3C%2FSTRONG%3E.%20This%20will%20launch%20the%20Metro%20packager%2C%20which%20will%20serve%20all%20the%20React%20Native%20components%20to%20your%20application.%20Once%20the%20dependency%20graph%20has%20been%20loaded%2C%20you%20can%20open%20the%20Start%20menu%20and%20launch%20the%20Windows%20application%20you%20have%20just%20deployed%20from%20Visual%20Studio.%20If%20you%20have%20done%20everything%20in%20the%20correct%20way%2C%20you%20will%20see%20the%20very%20simple%20UI%20we%20have%20built%20in%20our%20component.%20By%20pressing%20the%20button%20you%20will%20invoke%20the%20native%20module%20and%20you%20will%20see%20the%20model%20of%20your%20device%20being%20displayed%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ReactNativeApp.png%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F161931i3F5738A5D5FF1338%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22ReactNativeApp.png%22%20alt%3D%22ReactNativeApp.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22improving-the-code%22%20id%3D%22toc-hId-611340313%22%20id%3D%22toc-hId--1855070487%22%3EImproving%20the%20code%3C%2FH3%3E%0A%3CP%3EIf%20you%20compare%20this%20development%20experience%20with%20the%20one%20you%20have%20when%20you%20add%20a%203rd%20party%20module%20to%20your%20project%20using%20yarn%20or%20npm%2C%20you%20realize%20that%20it's%20quite%20different.%20In%20such%20a%20case%2C%20in%20fact%2C%20you%20don't%20have%20to%20deal%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%3B%20or%20you%20don't%20need%20to%20use%20callbacks%20to%20call%20the%20various%20methods.%20Let's%20use%20again%20the%20example%20of%20the%20popular%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAsyncStorage%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emodule.%20If%20you%20want%20to%20store%20some%20data%20in%20the%20storage%2C%20you%20just%20import%20a%20reference%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EAsyncStorage%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20and%20then%20you%20call%20an%20asynchronous%20method%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EsetItem%3C%2FCODE%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20AsyncStorage%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'%40react-native-community%2Fasync-storage'%3C%2FSPAN%3E%3B%0A%0AstoreData%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20AsyncStorage.setItem(%3CSPAN%20class%3D%22hljs-string%22%3E'%40storage_Key'%3C%2FSPAN%3E%2C%20%3CSPAN%20class%3D%22hljs-string%22%3E'stored%20value'%3C%2FSPAN%3E)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ECan%20we%20achieve%20the%20same%20goal%20with%20the%20native%20module%20we%20have%20just%20built%3F%20The%20answer%20is%20yes!%20We%20just%20need%20to%20build%20a%20JavaScript%20wrapper%2C%20that%20will%20make%20consuming%20our%20native%20module%20more%20straightforward.%3C%2FP%3E%0A%3CP%3EIn%20Visual%20Studio%20Code%20add%20a%20new%20file%20in%20your%20React%20Native%20project%20and%20call%20it%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESampleComponent.js%3C%2FSTRONG%3E.%20First%2C%20let's%20import%20the%20same%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ENativeModules%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject%20we%20have%20previously%20imported%20in%20the%20main%20component%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3ENow%2C%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-JavaScript%20Promises%2C%20we%20can%20build%20a%20wrapper%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetResult()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%20Thanks%20to%20Promises%2C%20we%20can%20enable%20an%20easier%20approach%20to%20consume%20our%20asynchronous%20API%2C%20thanks%20to%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords.%20If%20you%20have%20some%20C%23%20background%2C%20this%20approach%20is%20similar%20to%20use%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETaskCompletionSource%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%20to%20build%20asynchronous%20operations%20that%20returns%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ETask%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject-%3C%2FP%3E%0A%3CP%3EThis%20is%20how%20we%20can%20wrap%20the%20method%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Eexport%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Econst%3C%2FSPAN%3E%20getDeviceModel%20%3D%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-params%22%3E()%3C%2FSPAN%3E%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-built_in%22%3EPromise%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-function%22%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresolve%2C%20reject%3C%2FSPAN%3E)%20%3D%26gt%3B%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20NativeModules.SampleComponent.getDeviceModel(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eresult%2C%20error%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(error)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20reject(error)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eelse%3C%2FSPAN%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20resolve(result)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D)%0A%20%20%20%20%7D)%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThe%20method%20returns%20a%20new%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EPromise%3C%2FCODE%3E%2C%20which%20requires%20us%20to%20fulfill%20two%20objects%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CCODE%3Eresolve%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20completed%20successfully.%3C%2FLI%3E%0A%3CLI%3E%3CCODE%3Ereject%3C%2FCODE%3E%2C%20which%20is%20invoked%20when%20the%20operation%20has%20failed.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EInside%20the%20Promise%20we%20invoke%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%2C%20in%20the%20same%20way%20we%20were%20doing%20before%20in%20the%20component.%20The%20only%20difference%20is%20that%2C%20in%20this%20case%2C%20once%20the%20callback%20is%20completed%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresult%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eresolve()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod%20in%20case%20of%20success%3B%20otherwise%2C%20we%20pass%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eerror%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereject()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Emethod.%3C%2FP%3E%0A%3CP%3ENow%20that%20we%20have%20built%20our%20wrapper%2C%20we%20can%20simplify%20the%20component%20we%20have%20previously%20built.%20First%2C%20remove%20the%20following%20line%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20%7B%20NativeModules%20%7D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'react-native'%3C%2FSPAN%3E%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThen%20replace%20it%20with%20the%20following%20one%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20*%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eas%3C%2FSPAN%3E%20SampleComponent%20%3CSPAN%20class%3D%22hljs-keyword%22%3Efrom%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'.%2FSampleComponent'%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20import%20will%20expose%20the%20functions%20we%20have%20defined%20in%20our%20wrapper%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eobject.%20Now%20you%20can%20change%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EgetModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20simply%20with%20this%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22language-javascript%20hljs%22%3EgetModel%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%20()%20%3D%26gt%3B%20%7B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20model%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eawait%3C%2FSPAN%3E%20SampleComponent.getDeviceModel()%3B%0A%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ethis%3C%2FSPAN%3E.setState(%20%7B%20%3CSPAN%20class%3D%22hljs-attr%22%3Emodel%3C%2FSPAN%3E%3A%20model%7D)%3B%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EAs%20you%20can%20see%2C%20thanks%20to%20Promises%20and%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ekeywords%2C%20the%20code%20is%20simpler%20to%20write%20and%20read.%20We%20just%20need%20to%20mark%20the%20function%20as%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Easync%3C%2FCODE%3E%2C%20then%20call%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3ESampleComponent.getDeviceModel()%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efunction%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Eawait%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eprefix.%20Since%20the%20asynchronous%20operation%20is%20managed%20for%20us%2C%20we%20can%20treat%20it%20like%20if%20it's%20synchronous%20and%20just%20store%20in%20a%20variable%20the%20result%2C%20which%20will%20contain%20the%20device%20model.%20Since%20we%20aren't%20using%20callbacks%2C%20we%20can%20also%20set%20the%20state%20directly%20by%20calling%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ethis.setState()%3C%2FCODE%3E.%20If%20you%20are%20a%20C%23%20developer%2C%20everything%20should%20be%20very%20familiar%2C%20since%20it's%20the%20same%20async%20and%20await%20approach%20supported%20by%20C%23.%3C%2FP%3E%0A%3CP%3EThat's%20it!%20Now%20launch%20the%20application%20again.%20In%20this%20case%20we%20didn't%20touch%20the%20native%20project%2C%20so%20if%20the%20Metro%20packager%20was%20still%20running%2C%20we%20should%20already%20be%20seeing%20the%20updated%20version.%20Of%20course%20there%20won't%20be%20any%20difference%2C%20since%20we%20didn't%20change%20the%20UI%20or%20the%20behavior%2C%20but%20the%20code%20is%20easier%20to%20read%20and%20maintain%20now.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22exporting-the-module%22%20id%3D%22toc-hId--1196114150%22%20id%3D%22toc-hId-632442346%22%3EExporting%20the%20module%3C%2FH3%3E%0A%3CP%3ESo%20far%2C%20we%20have%20added%20the%20native%20module%20implementation%20directly%20in%20the%20project.%20What%20if%20we%20want%20to%20create%20a%20true%20self-contained%20module%2C%20that%20we%20can%20install%20using%20yarn%20or%20npm%20like%20any%20other%203rd%20party%20module%3F%20Well%2C%20unfortunately%20the%20story%20isn't%20complete%20for%20Windows%20yet.%20By%20following%20the%20documentation%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-available%20on%20GitHub%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eit's%20easy%20to%20create%20the%20skeleton%20of%20the%20module.%20We%20just%20need%20to%20create%20a%20new%20React%20Native%20module%20project%2C%20using%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ecreate-react-native-module%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ECLI%20tool%2C%20add%20the%20React%20Native%20for%20Windows%20package%20and%20then%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EInclude%20a%20folder%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Ewindows%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewith%20the%20Windows%20Runtime%20Component%20we%20have%20developed.%3C%2FLI%3E%0A%3CLI%3EOptionally%20include%20any%20JavaScript%20wrapper%20we%20might%20have%20created%20to%20make%20easier%20consuming%20the%20module.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EIf%20you%20already%20have%20a%20module%20with%20iOS%20and%20Android%20support%2C%20you'll%20just%20need%20instead%20to%20follow%20step%201%20and%20include%20the%20windows%20folder%20with%20the%20Windows%20Runtime%20Component%20in%20your%20existing%20project.%3C%2FP%3E%0A%3CP%3EHowever%2C%20regardless%20of%20your%20scenario%2C%20the%20current%20React%20Native%20for%20Windows%20implementation%20lacks%20an%20important%20feature%20called%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elinking%3C%2FSTRONG%3E.%20You'll%20remember%20that%2C%20in%20the%20previous%20section%2C%20we%20had%20to%20manually%20edit%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile%20of%20the%20React%20Native%20project%20to%20load%2C%20through%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3EReactPackageProvider%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eclass%2C%20our%20Windows%20Runtime%20Component.%20On%20Android%20and%20iOS%20this%20operation%20isn't%20needed%20thanks%20to%20linking.%20You%20just%20need%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CCODE%3Ereact-native%20link%3C%2FCODE%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%3A%20it%20will%20take%20care%20of%20everything%20for%20you%2C%20without%20needing%20to%20manually%20edit%20the%20Android%20and%20iOS%20projects.%20React%20Native%200.60%20has%20brought%20linking%20to%20the%20next%20level%2C%20by%20introducing%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Eautomatic%20linking%3C%2FSTRONG%3E.%20You%20don't%20even%20have%20to%20run%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Elink%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ecommand%20anymore%3B%20just%20add%20the%20package%20to%20your%20project%20and%20React%20Native%20will%20take%20of%20everything%20else%20for%20you.%20The%20React%20Native%20implementation%20for%20iOS%20and%20Android%20will%20automatically%20load%20all%20the%203rd%20party%20modules%20that%20have%20been%20added%20to%20the%20project.%20This%20feature%20isn't%20available%20on%20Windows%20yet%20and%2C%20as%20such%2C%20if%20you%20create%20an%20independent%20module%20and%20you%20publish%20it%20on%20NPM%2C%20you%20will%20still%20need%20to%20manually%20open%20the%20React%20Native%20for%20Windows%20solution%20in%20Visual%20Studio%20and%20register%20the%20module%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp.cpp%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efile.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20important%20information%20to%20highlight%20is%20the%20language%20choice%20for%20your%20module.%20C%2B%2B%20has%20a%20performance%20advantage%20over%20C%2B%2B%2C%20since%20it%20doesn't%20need%20to%20pull%20in%20the%20whole%20CLR%20in%20the%20React%20Native%20project.%20As%20such%2C%20especially%20if%20you're%20planning%20to%20share%20your%20module%20with%20the%20community%2C%20you%20should%20seriously%20consider%20to%20use%20C%2B%2B.%20If%2C%20instead%2C%20you're%20aiming%20to%20use%20your%20module%20only%20in%20your%20project%20and%20you%20have%20verified%20that%20the%20performance%20trade%20off%20doesn't%20heavily%20affect%20your%20application%2C%20it's%20fine%20to%20keep%20using%20C%23.%3C%2FP%3E%0A%3CH3%20id%3D%22publishing-the-application%22%20id%3D%22toc-hId-1291398683%22%20id%3D%22toc-hId--1175012117%22%3EPublishing%20the%20application%3C%2FH3%3E%0A%3CP%3ECompared%20to%20the%20last%20time%20I%20wrote%20about%20React%20Native%20for%20Windows%2C%20there's%20a%20big%20news!%20Now%20you%20can%20create%20a%20deployable%20version%20of%20the%20application%3A%20an%20AppX%20%2F%20MSIX%20package%20which%20is%20self-contained%20and%20that%20doesn't%20need%20the%20Metro%20packager%20to%20be%20up%20%26amp%3B%20running.%20This%20way%2C%20you%20can%20publish%20the%20application%20on%20the%20Microsoft%20Store%20or%20using%20one%20of%20the%20many%20supported%20deployment%20techniques%20(sideloading%2C%20SSCM%2C%20Intune%2C%20etc.).%20To%20achieve%20this%20goal%20just%20start%20the%20publishing%20process%2C%20like%20you%20would%20do%20with%20any%20Universal%20Windows%20Platform%20application.%20Right%20click%20on%20the%20React%20Native%20project%20in%20Visual%20Studio%2C%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPublish%20%E2%86%92%20Create%20app%20packages%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20follow%20the%20wizard.%20Just%20make%20sure%2C%20in%20the%20package%20configuration%20step%2C%20to%20choose%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ERelease%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20configuration%20mode.%20This%20way%2C%20all%20the%20React%20Native%20resources%20will%20be%20bundled%20together%2C%20removing%20the%20requirement%20of%20having%20the%20Metro%20packager%20up%20%26amp%3B%20running.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22wrapping-up%22%20id%3D%22toc-hId--516055780%22%20id%3D%22toc-hId-1312500716%22%3EWrapping%20up%3C%2FH3%3E%0A%3CP%3EIn%20this%20post%20we%20have%20seen%20how%20you%20can%20build%20native%20modules%20for%20React%20Native%20for%20Windows.%20This%20will%20allow%20us%20to%20build%20applications%20using%20the%20React%20stack%20but%2C%20at%20the%20same%20time%2C%20leverage%20native%20features%20provided%20by%20Windows%2C%20like%20toast%20notifications%2C%20access%20to%20Bluetooth%20APIs%2C%20file%20system%2C%20etc.%20We%20have%20also%20learned%20how%20we%20can%20distribute%20an%20application%20built%20with%20React%20Native%2C%20either%20via%20the%20Microsoft%20Store%20or%20one%20of%20the%20many%20techniques%20supported%20by%20MSIX%2C%20like%20sideloading%20or%20Microsoft%20Intune.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20the%20sample%20I've%20built%20for%20this%20post%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E-ERR%3AREF-NOT-FOUND-on%20GitHub.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20coding!%3C%2FP%3E%3C%2FREACTPACKAGEPROVIDER%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1067893%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20this%20blog%20post%20we're%20going%20to%20learn%20how%20we%20can%20build%20such%20a%20native%20module%20with%20Windows%20support%2C%20so%20that%20we%20can%20access%20to%20native%20Windows%20APIs%20when%20our%20React%20Native%20application%20is%20running%20on%20Windows.%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Microsoft

Update on 2nd January 2020:

The latest version of React Native for Windows has changed the namespace in which the IReactPackageProvider interface has been implemented. The previous one was:

 

 

 

Microsoft.ReactNative.Bridge;

 

 

 

while the new one is:

 

 

 

Microsoft.ReactNative;

 

 

 

The snippets in the post have been updated to reflect this change.

 

 

React Native offers a wide range of modules to extend the core functionalities of the platform, developed either by the community or by the React team himself. These modules range from UI controls, helpers and services. Some of them are "generic" and they perform tasks which don't require access to any specific platform feature. For example, Redux is a very popular state management library used in React applications but since, by default, everything is stored in memory, it basically runs everywhere. In fact, the same library can be used either with web applications (using React) or native applications (using React Native).

 

However, there are many scenarios in the native development space where the only way to achieve a task is by interacting with the native APIs offered by the platform. Saving a file in the local storage; getting information about the device; accessing to the GPS are just a few examples. In this case, the module can't be generic, because each platform has its own way to access to native features. This is why React Native supports the concept of native modules: a module that is leveraged in the main application through JavaScript but that, under the hood, invokes a native component specific for the platform where the application is running. Being native, each component isn't built in JavaScript, but using the native language used by the platform. For example, take a look at the popular module AsyncStorage, which can be used to read and write files in the local storage. As you can see, we have a folder called ios, which contains a XCode project; the android folder, instead, contains some Java files. Both projects simply expose the same features, but implemented using the specific language and APIs from iOS and Android.

 

If you have some experience with Xamarin and Xamarin Forms, this approach will be familiar. It's the same exact concept, in fact, behind Xamarin Plugins: the entry point is a C# wrapper which, under the hood, calls Swift, Java or UWP code based on the platform where the application is running.

 

In this blog post we're going to learn how we can build such a native module with Windows support, so that we can access to native Windows APIs when our React Native application is running on Windows.

 

Create a React Native for Windows project

As first step, let's create a React Native project with Windows support. I won't explain all the steps, since they are very well documented on the official GitHub repository. Additionally, I already introduced React Native and the recently added Windows support in another article.

Once you have completed all the steps, open the windows folder inside the project and double click on the Visual Studio solution. As we have learned in the previous article, the solution contains a single application which is the host for our React Native content. In a regular scenario you won't need to touch the code here, since the whole development will happen in the JavaScript world. However, in our case we have to make an exception, since we need to interact with native Windows APIs to build our module.

 

Create the module with a Windows Runtime Component

Let's start by adding a new project to the solution, which type is Windows Runtime Component. The component will give us access to all the Universal Windows Platform APIs. Additionally, being a WinRT component, it can be consumed regardless of the language used to build the main application. As a consequence, you're free to create a C# or C++ component, based on the language you're most familiar with. We'll be able to leverage it from the main React Native host (which is built in C++) regardless.

In my case, C# is my favorite language, so I've chosen the Windows Runtime Component (C#) template. If you want to use C++, instead, you need to choose the Windows Runtime Component (C++/WinRT) template. If you don't see it, you can install it using this extension. Pay attention to not use the C++/CX template, because this approach to build C++ components for the Universal Windows Platform has been deprecated.

 

WindowsRuntimeComponent.png

 

Once the project has been created, you need to reference a couple of projects which are already included as part of the React Native for Windows solution. Right click on the project you have just created and choose Add → Reference.

  • From the Projects section, choose Microsoft.ReactNative. This is the core React Native implementation for Windows.
  • From the Shared Projects section, choose Microsoft.ReactNative.SharedManaged. This project will give us access to C# helpers that will make easy to build a native module. If you're using C++, the project to reference is called Microsoft.ReactNative.Cxx.

These projects are very important because they define many attributes which will allow you to export the native code to JavaScript. This way, the developers who are going to use your module in their React Native projects don't need to know anything about C++, C# or Windows 10 APIs. They just need to use standard and plain JavaScript code.

 

Before starting to write some code, expand the References section of the project, select the Microsoft.ReactNative library, right click on it and choose Properties. Set Copy Local to false, to make sure that there are no conflicts with the main application.

Now we can start building our module. We're going to create a simple one to expose the information about the model of the device where the application is running. Let's start by renaming the default class included in the project with a more meaningful name, like SampleComponent. This should trigger the renaming also of the class declared inside the code.

Now we just need to define one or more methods, that will be exposed to the React Native application. In our case, we're going to define a single method that will return the current device name, using the EasClientDeviceInformation class included in the Universal Windows Platform:

 

using Windows.Security.ExchangeActiveSyncProvisioning;

namespace SampleReactModule
{
    class SampleComponent
    {
        public string GetDeviceModel()
        {
            EasClientDeviceInformation info = new EasClientDeviceInformation();
            return info.SystemProductName;
        }
    }
}

The next step is to leverage the attributes provided by the Microsoft.ReactNative library to export the class and the method we have created to React Native. In our scenario we're going to use two of the many available ones:

  • [ReactModule], which we're using to decorate the whole class.
  • [ReactMethod], which we're using to decorate every single method we want to expose.

This is the final look of our class:

 

using Microsoft.ReactNative.Managed;
using Windows.Security.ExchangeActiveSyncProvisioning;

namespace SampleReactModule
{
    [ReactModule]
    class SampleComponent
    {
        [ReactMethod("getDeviceModel")]
        public string GetDeviceModel()
        {
            EasClientDeviceInformation info = new EasClientDeviceInformation();
            return info.SystemProductName;
        }
    }
}

Notice that we have passed the getDeviceModel value as parameter of the ReactMethod attribute. This is how we define the name of the method that will be available through JavaScript to the React Native project.

There are many other attributes, which can be used to expose additional stuff to the React Native application, like properties or event handlers. They are all documented here.

The next thing we need is a ReactPackageProvider, which is a special object that will allow the React Native project to load all the modules exposed by our library. By default, in fact, a React Native application loads only the built-in modules. Right click on the project and choose Add → Class. Name it ReactPackageProvider. The class is very simple:

 

using Microsoft.ReactNative;
using Microsoft.ReactNative.Managed;

namespace SampleReactModule
{
    public sealed class ReactPackageProvider: IReactPackageProvider
    {
        public void CreatePackage(IReactPackageBuilder packageBuilder)
        {
            packageBuilder.AddAttributedModules();
        }
    }
}

It just needs to implement the IReactPackageProvider interface, which will require you to implement the CreatePackage() method. Inside it we leverage the packageBuilder object and the AddAttributedModules() method to load all the modules we have decorated with the [ReactModule] attribute inside our project.

 

Register the module in the React Native application

As already mentioned, by default React Native for Windows registers only the modules which are included in the main project. If we would have created the SampleComponent class inside the main React Native project, we wouldn't have needed any additional step. However, in our case we are using a separate Windows Runtime Component, which allows us to leverage a different language (C#), so we need an extra step to register the library in the main application.

 

First, right click on the React Native for Windows project and choose Add → Reference. Select from the list the name of the Windows Runtime Component you have just created (in my sample, it's SampleReactModule) and press Ok.

 

Expand the App.xaml node in the main React Native project and double click on the App.cpp file. Inside the App constructor you will find the following entry:

 

PackageProviders().Append(make<ReactPackageProvider>());

This is the code which loads all the modules that are included in the main project. Let's add below another registration for our new library:

 

PackageProviders().Append(winrt::SampleReactModule::ReactPackageProvider());

SampleReactModule is the name of the Windows Runtime Component we have previously created, thus it's the namespace that contains our ReactPackageProvider implementation. To make this code compiling we need also to include the header file of our module at the top:

 

#include "winrt/SampleReactModule.h"

This is how the whole App.cpp file should look like:

 

#include "pch.h"

#include "App.h"
#include "ReactPackageProvider.h"
#include "winrt/SampleReactModule.h"

using namespace winrt::NativeModuleSample;
using namespace winrt::NativeModuleSample::implementation;

/// <summary>
/// Initializes the singleton application object.  This is the first line of
/// authored code executed, and as such is the logical equivalent of main() or
/// WinMain().
/// </summary>
App::App() noexcept
{
    MainComponentName(L"NativeModuleSample");

#if BUNDLE
    JavaScriptBundleFile(L"index.windows");
    InstanceSettings().UseWebDebugger(false);
    InstanceSettings().UseLiveReload(false);
#else
    JavaScriptMainModuleName(L"index");
    InstanceSettings().UseWebDebugger(true);
    InstanceSettings().UseLiveReload(true);
#endif

#if _DEBUG
    InstanceSettings().EnableDeveloperMenu(true);
#else
    InstanceSettings().EnableDeveloperMenu(false);
#endif

    PackageProviders().Append(make<ReactPackageProvider>()); // Includes all modules in this project
    PackageProviders().Append(winrt::SampleReactModule::ReactPackageProvider());


    InitializeComponent();

    // This works around a cpp/winrt bug with composable/aggregable types tracked
    // by 22116519
    AddRef();
    m_inner.as<::IUnknown>()->Release();
}

 

Using the module from JavaScript

That's it! Now we can move to the React Native project to start using the module we have just built from JavaScript. Open the folder which contains your React Native project with your favorite web editor. For me, it's Visual Studio Code. For simplicity, I've implemented the component which uses the native module directly in the App.js file of my React Native project, so that it will be the startup page.

The first step is importing the NativeModule object exposed by React Native in our component:

 

import { NativeModules } from 'react-native';

Our module will be exposed through this object, by leveraging the name of the class we have decorated with the [ReactModule] attribute. In our case, it's SampleComponent, so we can use the following code to access to the GetDeviceModule() method:

 

NativeModules.SampleComponent.getDeviceModel();

Notice that we can reference the method with the lowercase name, getDeviceModel(), thanks to the parameter we have passed to the [ReactMethod] attribute. However, by default the methods exposed by native modules are implemented in an asynchronous way using callbacks. As such, if we want to consume the getDeviceModel() method, we need to use the following approach:

 

getModel = () => {
  var current = this;
  NativeModules.SampleComponent.getDeviceModel(function(result) {
    current.setState({model: result});
  })
}

The method accepts a function, that is invoked once the asynchronous operation is completed. Inside this function we receive, as parameter, the result returned by our native method (in our case, the model of the device). In our sample, we store it inside the component's state, so that we can display it in the user interface using the JSX syntax:

 

<Text>Model: {this.state.model}</Text>

Before calling the setState() method, however, we need to save a reference to the main context. Inside the callback, in fact, we have moved to a different context, so we don't have access to the helpers exposed by React Native.

Below you can find the full definition of our component:

 

import React, {Fragment} from 'react';
import {
  StyleSheet,
  View,
  Text,
  StatusBar,
  Button
} from 'react-native';


import { NativeModules } from 'react-native';

class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      model: '',
    }
  }

  getModel = () => {
    var current = this;
    NativeModules.SampleComponent.getDeviceModel(function(result) {
      current.setState({model: result});
    })
  }

  render() {
    return (
      <View style={styles.sectionContainer}>
        <StatusBar barStyle="dark-content" />
        <View>
          <Button title="Get model" onPress={this.getModel} />
          <Text>Model: {this.state.model}</Text>
        </View>
      </View>
    );
  }
 
};

//styles definition

export default App;

If you're familiar with React Native, the code should be easy to understand:

  1. We have defined a function called getModel(), which takes care of interacting with our native module. The model of the device is stored inside the component's state, using the setState() function provided by React Native.
  2. The render() methods defines the UI component, using the JSX syntax. The UI is very simple:
    • We have a <Button>, which invokes the getModel() function by leveraging the onPress event.
    • We have a <Text>, which displays the value of the model property stored inside the state.

 

Testing the code

Now it's time to test the code! First, right click on the React Native project in Visual Studio and choose Deploy. Before doing it, however, use the Configuration Manager dropdown to make sure you're targeting the right CPU architecture. By default, in fact, the solution will target ARM, so you will have to switch to x86 or x64. If it's the first time you build it, it will take a while since C++ compilation isn't exactly fast =) Once it's done, open a command prompt on the folder which contains your React Native project and type yarn start. This will launch the Metro packager, which will serve all the React Native components to your application. Once the dependency graph has been loaded, you can open the Start menu and launch the Windows application you have just deployed from Visual Studio. If you have done everything in the correct way, you will see the very simple UI we have built in our component. By pressing the button you will invoke the native module and you will see the model of your device being displayed:

 

ReactNativeApp.png

Improving the code

If you compare this development experience with the one you have when you add a 3rd party module to your project using yarn or npm, you realize that it's quite different. In such a case, in fact, you don't have to deal with the NativeModules object; or you don't need to use callbacks to call the various methods. Let's use again the example of the popular AsyncStorage module. If you want to store some data in the storage, you just import a reference to the AsyncStorage object and then you call an asynchronous method called setItem:

 

import AsyncStorage from '@react-native-community/async-storage';

storeData = async () => {
    await AsyncStorage.setItem('@storage_Key', 'stored value')
}

Can we achieve the same goal with the native module we have just built? The answer is yes! We just need to build a JavaScript wrapper, that will make consuming our native module more straightforward.

In Visual Studio Code add a new file in your React Native project and call it SampleComponent.js. First, let's import the same NativeModules object we have previously imported in the main component:

 

import { NativeModules } from 'react-native';

Now, using JavaScript Promises, we can build a wrapper to the getResult() method. Thanks to Promises, we can enable an easier approach to consume our asynchronous API, thanks to the async and await keywords. If you have some C# background, this approach is similar to use the TaskCompletionSource class to build asynchronous operations that returns a Task object-

This is how we can wrap the method:

 

import { NativeModules } from 'react-native';

export const getDeviceModel = () => {
    return new Promise((resolve, reject) => {
        NativeModules.SampleComponent.getDeviceModel(function(result, error) {
            if (error) {
                reject(error);
            }
            else {
                resolve(result);
            }
        })
    })
}

The method returns a new Promise, which requires us to fulfill two objects:

  • resolve, which is invoked when the operation has completed successfully.
  • reject, which is invoked when the operation has failed.

Inside the Promise we invoke the getDeviceModel() method, in the same way we were doing before in the component. The only difference is that, in this case, once the callback is completed we pass the result to the resolve() method in case of success; otherwise, we pass the error to the reject() method.

Now that we have built our wrapper, we can simplify the component we have previously built. First, remove the following line:

 

import { NativeModules } from 'react-native';

Then replace it with the following one:

 

import * as SampleComponent from './SampleComponent'

This import will expose the functions we have defined in our wrapper through the SampleComponent object. Now you can change the getModel() function simply with this code:

 

getModel = async () => {
  var model = await SampleComponent.getDeviceModel();
  this.setState( { model: model});
}

As you can see, thanks to Promises and the async and await keywords, the code is simpler to write and read. We just need to mark the function as async, then call the SampleComponent.getDeviceModel() function with the await prefix. Since the asynchronous operation is managed for us, we can treat it like if it's synchronous and just store in a variable the result, which will contain the device model. Since we aren't using callbacks, we can also set the state directly by calling this.setState(). If you are a C# developer, everything should be very familiar, since it's the same async and await approach supported by C#.

That's it! Now launch the application again. In this case we didn't touch the native project, so if the Metro packager was still running, we should already be seeing the updated version. Of course there won't be any difference, since we didn't change the UI or the behavior, but the code is easier to read and maintain now.

 

Exporting the module

So far, we have added the native module implementation directly in the project. What if we want to create a true self-contained module, that we can install using yarn or npm like any other 3rd party module? Well, unfortunately the story isn't complete for Windows yet. By following the documentation available on GitHub it's easy to create the skeleton of the module. We just need to create a new React Native module project, using the create-react-native-module CLI tool, add the React Native for Windows package and then:

 

  1. Include a folder called windows with the Windows Runtime Component we have developed.
  2. Optionally include any JavaScript wrapper we might have created to make easier consuming the module.

If you already have a module with iOS and Android support, you'll just need instead to follow step 1 and include the windows folder with the Windows Runtime Component in your existing project.

However, regardless of your scenario, the current React Native for Windows implementation lacks an important feature called linking. You'll remember that, in the previous section, we had to manually edit the App.cpp file of the React Native project to load, through the ReactPackageProvider class, our Windows Runtime Component. On Android and iOS this operation isn't needed thanks to linking. You just need to run the react-native link command: it will take care of everything for you, without needing to manually edit the Android and iOS projects. React Native 0.60 has brought linking to the next level, by introducing automatic linking. You don't even have to run the link command anymore; just add the package to your project and React Native will take of everything else for you. The React Native implementation for iOS and Android will automatically load all the 3rd party modules that have been added to the project. This feature isn't available on Windows yet and, as such, if you create an independent module and you publish it on NPM, you will still need to manually open the React Native for Windows solution in Visual Studio and register the module in the App.cpp file.

 

Another important information to highlight is the language choice for your module. C++ has a performance advantage over C++, since it doesn't need to pull in the whole CLR in the React Native project. As such, especially if you're planning to share your module with the community, you should seriously consider to use C++. If, instead, you're aiming to use your module only in your project and you have verified that the performance trade off doesn't heavily affect your application, it's fine to keep using C#.

Publishing the application

Compared to the last time I wrote about React Native for Windows, there's a big news! Now you can create a deployable version of the application: an AppX / MSIX package which is self-contained and that doesn't need the Metro packager to be up & running. This way, you can publish the application on the Microsoft Store or using one of the many supported deployment techniques (sideloading, SSCM, Intune, etc.). To achieve this goal just start the publishing process, like you would do with any Universal Windows Platform application. Right click on the React Native project in Visual Studio, choose Publish → Create app packages and follow the wizard. Just make sure, in the package configuration step, to choose Release as configuration mode. This way, all the React Native resources will be bundled together, removing the requirement of having the Metro packager up & running.

 

Wrapping up

In this post we have seen how you can build native modules for React Native for Windows. This will allow us to build applications using the React stack but, at the same time, leverage native features provided by Windows, like toast notifications, access to Bluetooth APIs, file system, etc. We have also learned how we can distribute an application built with React Native, either via the Microsoft Store or one of the many techniques supported by MSIX, like sideloading or Microsoft Intune.

 

You can find the sample I've built for this post on GitHub.

 

Happy coding!