简体   繁体   English

React / JSX范围

[英]React/JSX Scope

Okay so I'm trying to intergrate React into an existing codebase. 好的,所以我试图将React集成到现有的代码库中。 Currently we have a single page web-app that is operated by a common.js, however I have noticed that if JSX files or at least script files that are loaded as 'type="text/jsx"' in the HTMl file fail to appear within the scope of JS files. 当前,我们有一个由common.js操作的单页Web应用程序,但是我注意到,如果HTMl文件中的JSX文件或至少以'type =“ text / jsx”'形式加载的脚本文件无法出现在JS文件范围内。 This creates a problem as we now have no way of manipulating the React components after initialization without refactoring an obscene amount of code. 这带来了一个问题,因为我们现在无法在初始化后不重构大量代码的情况下操纵React组件。 Common.js can't be transformed to JSX because we have external files/libraries that rely on it's scope. Common.js无法转换为JSX,因为我们拥有依赖于它的作用域的外部文件/库。

You can "compile" your jsx files directly from the terminal. 您可以直接从终端“编译”您的jsx文件。 That way, you don't have to put type="text/jsx" because it will just be js code. 这样,您不必放入type="text/jsx"因为它只是js代码。

Here's an npm command line compiler called jsx 这是一个名为jsx的npm命令行编译器

If you're using NodeJS for your server, you can use express-jsx middleware to compile your code on the fly. 如果您将NodeJS用于服务器,则可以使用express-jsx中间件即时编译代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM