# ReactJS OWA example

**URL:** <https://talk.openmrs.org/t/reactjs-owa-example/9496>\
**Category:** Development\
**Tags:** reactjs\
**Created:** [January 9, 2017, 8:52pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496 "2017-01-09T20:52:18Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [January 9, 2017, 8:52pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/1 "2017-01-09T20:52:19Z")

</div>

I took some time last week to play around with ReactJS, and I created an OWA example at [https://github.com/djazayeri/openmrs-owa-reactexample](https://github.com/djazayeri/openmrs-owa-reactexample)

If this is something we want to support, we need to make some changes to the yeoman generator (which currently lets you start with jQuery or AngularJS), e.g. to add the react preset to webpack.

All in all I found it pretty easy. ReactJS only handles the view/presentation layer, and it makes it easy to write components (actually, you can _only_ write components). Based on this very limited experience, I think I prefer react’s model of “writing JS functions that return HTML” as compared to angular’s usage of ng-show/hg-nide/ng-repeat.

Next I will refactor it to use a Redux store, so here is a permalink to the current simpler code: [https://github.com/djazayeri/openmrs-owa-reactexample/tree/caadf15be33ff26aabe47eb3600f65fd1043530c](https://github.com/djazayeri/openmrs-owa-reactexample/tree/caadf15be33ff26aabe47eb3600f65fd1043530c)

FYI, on the Bahmni distribution our plan is to migrate incrementally in the direction of react, and use redux to get a better handle on having shared application state that can be modified by different pluggable apps and components (some of which are legacy ones written in Angular 1). And we’ve started our first efforts in this direction. We’ll share more once we have something demonstrable to show!

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [January 11, 2017, 1:51am UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/2 "2017-01-11T01:51:12Z")

</div>

Today I modified this example to use Redux for state storage.

It actually took me the entire day to wrap my head around some of this. My biggest confusion was that using react-router and redux together is awkward (and I was blocked for a few hours until I found the onEnter option). React+Redux is a more complicated architecture than just, and though the react-redux library makes the connection pretty painless, one does need to set conventions for smart container components vs presentation components vs the wrappers that you generate with react-redux. And I didn’t do this in my example.

I definitely see how the Redux Action -\> Reducer -\> Store data architecture is good for large-scale applications, but it takes some getting used to.

About routing, I will say that deep-linking just works in this example without me having thought about it, whereas I’ve rarely gotten it work right with angular, even in production code.

My changes are here: [https://github.com/djazayeri/openmrs-owa-reactexample/commit/ff71508bbf4aea0d947de37daf438b65c3f1e7bc](https://github.com/djazayeri/openmrs-owa-reactexample/commit/ff71508bbf4aea0d947de37daf438b65c3f1e7bc)

---

<div class="post-metadata">

**Author:** ![raff](https://talk.openmrs.org/user_avatar/talk.openmrs.org/raff/32/11894_2.png) [@raff](https://talk.openmrs.org/u/raff)\
**Post date:** [January 11, 2017, 11:10am UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/3 "2017-01-11T11:10:39Z")

</div>

@darius, would you use Redux for any new ReactJS project i.e. include it in OWA generator?

---

<div class="post-metadata">

**Author:** ![mksd](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mksd/32/11729_2.png) [@mksd](https://talk.openmrs.org/u/mksd)\
**Post date:** [January 11, 2017, 11:15am UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/4 "2017-01-11T11:15:28Z")

</div>

For those who like me had never heard of Redux, I found this useful: [http://www.youhavetolearncomputers.com/blog/2015/9/15/a-conceptual-overview-of-redux-or-how-i-fell-in-love-with-a-javascript-state-container](http://www.youhavetolearncomputers.com/blog/2015/9/15/a-conceptual-overview-of-redux-or-how-i-fell-in-love-with-a-javascript-state-container)

It’s all really cool, but I’m not sure I fully understand where the benefits kick in 😶I guess I should debug your project to understand but I can’t do now.

It’s great that you’re producing this sample OWA, **very** useful.

---

<div class="post-metadata">

**Author:** ![lluismf](https://talk.openmrs.org/user_avatar/talk.openmrs.org/lluismf/32/770_2.png) [@lluismf](https://talk.openmrs.org/u/lluismf)\
**Post date:** [January 11, 2017, 2:39pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/5 "2017-01-11T14:39:49Z")

</div>

> [@darius](#):
>
> I definitely see how the Redux Action -\> Reducer -\> Store data architecture is good for large-scale applications, but it takes some getting used to.

Maybe it’s just for SPAs.

---

<div class="post-metadata">

**Author:** ![lluismf](https://talk.openmrs.org/user_avatar/talk.openmrs.org/lluismf/32/770_2.png) [@lluismf](https://talk.openmrs.org/u/lluismf)\
**Post date:** [January 11, 2017, 2:41pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/6 "2017-01-11T14:41:56Z")

</div>

I saw a technical presentation about Redux being used both in the UI and the backend. The backend part blew my mind 😮

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [January 12, 2017, 1:39am UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/7 "2017-01-12T01:39:23Z")

</div>

> [@raff](#):
>
> @darius, would you use Redux for any new ReactJS project i.e. include it in OWA generator?

Bahmni is going to be doing a UI rearchitecture based on using Redux as a shared store of application state, that can be used both by React apps/components, and Angular apps/components. (This is because we have a large amount of code written in Angular already, but want to gradually move to React without needing to rewrite everything.) @bharatak is spiking on this now, and he’ll share news when he’s ready (I’m really spoiling his surprise here).

I personally needed to get up to speed so that I can intelligently discuss this with him, which is why I did this example here.

So, I don’t know what I would recommend to a general OpenMRS developer looking to do a single OWA, but at some point we should have some Bahmni code using react+redux that can be leveraged against plain OpenMRS + REST + OWA.

I’ll submit a PR shortly to the generator that lets you bootstrap an OWA with just react, or with react+redux.

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [January 15, 2017, 4:04pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/8 "2017-01-15T16:04:42Z")

</div>

FYI the [latest Yeoman Generator](https://www.npmjs.com/package/generator-openmrs-owa) now lets you create a ReactJS or ReactJS+Redux OWA.

The generated project structure isn’t necessarily best-practice, it just copies what I did in my example here. But it saves you the trouble of figuring out how to set up webpack to handle jsx files, at least. 🙂

---

<div class="post-metadata">

**Author:** ![beapen](https://talk.openmrs.org/user_avatar/talk.openmrs.org/beapen/32/1710_2.png) [@beapen](https://talk.openmrs.org/u/beapen)\
**Post date:** [January 24, 2018, 3:16pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/9 "2018-01-24T15:16:01Z")

</div>

I have extended the example by @darius. This may be easier to use as a starter for new react-redux OWAs. Uses axios, logger, decorators, and react-layout.

> **[dermatologist/openmrs-owa-react-boilerplate](https://github.com/dermatologist/openmrs-owa-react-boilerplate)**
>
> openmrs-owa-react-boilerplate - An OpenMRS OWA Template Using React and Redux.

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [January 24, 2018, 3:50pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/10 "2018-01-24T15:50:57Z")

</div>

@beapen awesome! 😄

---

<div class="post-metadata">

**Author:** ![pascal](https://talk.openmrs.org/letter_avatar/pascal/32/6_449c533f586939b6e5f246632a46421f.png) [@pascal](https://talk.openmrs.org/u/pascal)\
**Post date:** [January 24, 2018, 4:14pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/11 "2018-01-24T16:14:30Z")

</div>

@beapen, any interest in adding your boilerplate to [the generator](https://github.com/psbrandt/generator-openmrs-owa)?

---

<div class="post-metadata">

**Author:** ![beapen](https://talk.openmrs.org/user_avatar/talk.openmrs.org/beapen/32/1710_2.png) [@beapen](https://talk.openmrs.org/u/beapen)\
**Post date:** [January 24, 2018, 5:12pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/12 "2018-01-24T17:12:32Z")

</div>

@dkayiwa Thank You!

@pascal Sure. (I don’t know much about generators. I only know how to use them)

---

<div class="post-metadata">

**Author:** ![pascal](https://talk.openmrs.org/letter_avatar/pascal/32/6_449c533f586939b6e5f246632a46421f.png) [@pascal](https://talk.openmrs.org/u/pascal)\
**Post date:** [January 24, 2018, 5:23pm UTC](https://talk.openmrs.org/t/reactjs-owa-example/9496/13 "2018-01-24T17:23:29Z")

</div>

@beapen, the authoring docs are [here](http://yeoman.io/authoring/), but there are already some React temples [here](https://github.com/psbrandt/generator-openmrs-owa/tree/master/app/templates/scripts/react) that you can modify/extend to incorporate your awesome contribution!
