GithubHelp home page GithubHelp logo

noriller / react-reusability-poc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 324 KB

React: learn once, write the logic once, render it in React Web and React Native!

JavaScript 58.03% HTML 27.24% CSS 14.72%
javascript poc react react-hooks react-native reactjs

react-reusability-poc's Introduction

React Reusability POC

This is a proof of concept of how you can write React code once and render it in both Web and Native apps.

How to use

yarn install
yarn --global add expo-cli

yarn start # for react native
# yarn tunnel # if the normal way don't work or your phone is in another network
yarn dev # for react web

The humble object

Usually used for testing, you split the logic from the GUI and make the GUI humble.

This separations makes it easier to test the logic since you don't need to worry about the GUI and how to call the functions through it.

This also makes it easier to render the same logic in different components, even if those components will be rendered by different engines.

The POC

With that in mind, I used a basic create-expo-app and a create-react-app and "merged" them.

I made a Counter component split into the "logic", and then the "web" and "native" components.

Since React for web and for native has different needs and components to be able to render, each has it's own implementation. But the logic behind them is exactly the same and could be reused without problems.

For this example I wanted to have all components and logic next to each other, and while I do think that having everything next to each other improves the experience for writing everything, I know that it would take a lot of configuring stuff (transpiler, test, lint, etc).

Then again I used the most basic options just because I wanted to see if with minimal configuration I would be able to do this.

Making this better

For React Native, we pretty much "only" have expo as an alternative. For the Web part however... cra, vite, next, remix, redwood...

The idea I believe would be most stable and meta-framework agnostic to work and to deploy would be to make this into a monorepo.

We could neatly split the dependencies and config and then split the logic hooks from the web/native parts.

react-reusability-poc's People

Contributors

noriller avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.