0

I am working on an Electron-React app. I have some limited experience with React. So I am thinking about how to structure my app before I start coding. My app is really simple, it does not need to store anything persistently, so I do not require to use any storage Redux or db. I have read on a Reddit post, that a good practice is to separate the components into Controller and View components. In this manner, I can have states and logic in Controller components that is passed down to View components. I understand how to do something like this. Thinking about my use case, however, I am wondering how I could pass back the data from the View component to the Controller.

For example, there is an input text field on the front-end and a button, when the button is clicked, View component has to send the data from the input text field back to the Controller, which does some computations and sends back the outputs to View. So I am unsure about this communication life-cycle once some event happens in the View component and how to propagate it back up and then down again?

Nah
  • 1,690
  • 2
  • 26
  • 46
Naz
  • 2,012
  • 1
  • 21
  • 45
  • There is no such MVC (Model View Controller) concept in `ReactJS`. It is just style of declarative coding, where we write number of components, where each component have its own lifecycle and it can render child components as well. When you talk about `Electron` it's totally different thing. It just allows you to include any website or local HTML file and run in windows dialog (like desktop app). There is no `ReactJs` bounding on it. To learn about `React` see: https://medium.com/@baphemot/understanding-reactjs-component-life-cycle-823a640b3e8d Or just google. – Nah May 03 '18 at 10:10
  • I know there is no MVC. I am thinking about how to properly structure this app, and I like the idea of separating the logic and what gets shown on the front-end. I also know Electron has no React bounding (I actually started writing the app w/o React), but something like Electron-Forge gives you Electron+React integration. The reason you would want to use them in combination is if you want the ease of design in React (for example using SketchApp, and then easily design components). – Naz May 03 '18 at 10:15
  • @MuhammadHannan thx for the link. I think I can use this shouldComponentUpdate lifecycle method to update the `[View]` components once the `[Controller]` finishes with its computations – Naz May 03 '18 at 10:24

0 Answers0