Is it necessary to run react project without babel? - reactjs

Is it necessary to configure React Project without babel which is a transpiler for JavaScript (turning ES6 into code that runs in your browser) ? or with babel as es6 is necessary to use in React projects?

Well, Babel is not really needed but writing React apps without JSX is not something a sane person would do.
Writing React without Babel is not viable honestly.

Related

Why using Django and React requires so much extra packages?

I have been going through a tutorial (https://www.youtube.com/watch?v=GieYIzvdt2U) where you have to use Babel, Webpack, and Redux which are all complicated in their regards. Why we can not use "djangorestframework" as my API and get the information using that API from React using JS. What do I gain using all these packages or I can not simply use what I am suggesting?
React doesn't just use JavaScript, it also uses JSX which cannot be run natively on a client web browser. JSX is a syntax extension of JS and allows for you to simulate templating of HTML.
Babel is a compiler. It compiles React's language (JSX) into valid javascript so that it can run on a web browser.
Webpack is a bundler. It minifies your compiled JS and CSS files and optimises it so that it can run more efficiently on a client's machine. Babel and Webpack are essential to the running of React Apps and even creating a react app using the traditional create-react-app command initialises your development setup to use Babel and Webpack under the hood.
Redux is separate. Redux is a state management tool that is purely used for development purposes (simplifies or complicates it, that's for you to decide!). You don't have to use Redux, you could opt to do your own state management, or use React Context.
In the next part, you communicate with your Django API using a library called Axios. Babel, Webpack, and Redux won't have any impact on that.

Is any decorator necessary for using Mobx in React Native?

I tried to use Mobx to manage state in React Native Project(ADE is Expo).
I have just install Mobx and Mobx-react by npm.
But some article about Mobx I read is mentioning some decorators like legacy and ~~-0.
Now actually my Mobx sample code is working without decorators.
So, I am wondering these decorators are necessary or not in my Project?
In addition to this, if these are necessary, why I should use these.
JS decorators are essentially just syntactic sugar which currently are not part of the JS language but some transpilers such as Babel has integrated them in their latest implementations. Using them is totally your personal preference just like you can create a complete React app without using the JS classes. They make the code more readable. Since you are using Expo, you don't need to add anything to babel configurations to be able to use them. In my understanding Expo does this for you.

Why does React require Babel and Webpack to work?

I was looking at the wiki page of vue.js and saw this:
When compared to React development, Vue can be integrated to an
existing web application much more easily. Normally, a web application
can start using Vue immediately by simply including the Vue.js
JavaScript library. Usage with Webpack or Browserify, are not strictly
necessarily. This is in stark contrast to React development where
Usage with Webpack and Babel is unavoidable, therefore making
converting existing web application much more difficult.
Can someone explain why React needs webpack and babel? I thought you can just drop in the link to the CDN of React and it will work?
No, Babel and Webpack is not necessary for React stack. You can still find other alternatives to build your favourite stack such as Browserify and Gulp.
However, if you want to make things easier, I do recommend you learn and use Babel and Webpack together with React because:
You can use modules.
You can use JSX with ES6.
It support a lot of browsers
You can use more advanced features (async/await) etc
With webpack
You can use different loaders for sass, less, postcss etc
You can use different plugins to optimise your build such as Uglify, HotModuleReplacement, Chunks etc
There are many more advantages to use webpack which you can find here
Can someone explain why React needs webpack and babel? I thought you can just drop in the link to the CDN of React and it will work?
React doesn't "need" babel or webpack but the library is built on the concept of using ES6 javascript syntax and JSX (essentially HTML in JS).
React however can be used without ES6 and JSX which would remove the initial need for Babel but you would lose the potential benefits of ES6 and JSX.
Webpack is separate from React but commonly used in React projects for reasons MattYao mentioned.
In comparison to Vue, JSX to me brings the benefits of containing html, css and JS in one file/component which is what Single File Components in Vue also try to achieve. These would also require a build step using something like webpack as well.
React uses JSX syntax to make writing react more familiar to we the programmers. However, the browsers do not understand JSX. Therefore babel is required to convert your JSX into javascript which is then manipulated by ReactDom and then input into your DOM for the browsers to understand.

Webpack restrict only to use ES6 modules

Hi I am developing an application using React and Webpack and Gulp.
Webpack gives us the ability to use both CommonJS style and ES6 style.
But I want it to be consistent. I want to use only ES6 module style and want to throw an error if someone uses require syntax.
How to restrict webpack to use only one Module style?
Webpack scans your files. During this process, it uses Babel to transpile import statements into require statements, which Webpack understands. Bundled JS is output of this process. Often, it's unreadable for human.
What you should do is to use ESLint. Use some of ESLint rules/plugins.
To enforce imports, pick this one, for example.
https://www.npmjs.com/package/eslint-plugin-import
Use it in editor or as part of build step...
Note: Webpack2 supports native import statements

Can react-toolbox be rendered from the serverside from a isomorphic/universal app?

http://react-toolbox.com/ Looks really good, but they have a sass dependency. Is there a way to use react-toolbox in a isomorphic/universal app and render them from the server, or are the sass dependencies somehow declared within the components?
They recommend using a CSS loader in the webpack development build. This leads me to the conclusion that the CSS dependencies are within the React Components. Am I wrong?
Yes, it can be rendered on the server side.
A preferred way is to utilize Webpack build with css-loader and sass-loader. Take a look on webpack-isomorphic-tools as an example of the plugin which could help with a server-side rendering of the react apps.
In my current project, we are using a forked version of webpack-starter-kit. Both examples allow you to utilize react-toolbox for a universal app. I am sure you could find at least a dozen of similar setups on GitHub.

Resources