javascript - React 未捕获类型错误 : Cannot read property 'replace' of undefined

标签 javascript php reactjs

我在 React 中将 php 变量转换为 javascript 时遇到问题。

这是代码(内容是西类牙语):

var insertar = "<?php echo $insertar; ?>";

var phpCodeInsertar = React.createClass({

 render : function(){

     if(!insertar){

         return(

             <center id='descripcion-registro-fail'>
                 <h1 id='dr-fail-h1'>Error al registrarte</h1>
                 <ul id='dr-fail-ul'>
                     <li>&middot Comprueba que has escrito bien tus datos.</li>
                     <li>&middot Asegurate de que no estás registrado(en caso contrario no puedes hacerlo de nuevo).</li><br></br>
                     <li id='dr-fail-ul-li'>Si ya has realizado los pasos anteriores y el problema sigue apareciendo, ponte en contacto con el <a id='dr-fail-a'>soporte</a>.</li>
                 </ul>
             </center>

         ); 

     } else {

         return(

         <center id='descripcion-registro'>
             <h1 id='dr-h1'>Gracias por registrarte.</h1>
             <p id='dr-p'>
                 Se ha enviado un correo de confirmación a tu email,<br></br>
                 entra en el enlace que hay en él y sigue las instrucciones para<br></br>
                 confirmar tu cuenta.
             </p>
         </center>

         );

     }

 }

});

我的问题是: 当我渲染页面时,我看到以下消息: 未捕获类型错误:无法读取未定义的属性“替换”。

我认为 React 检测到“insertar”(一个 bool php 变量),就像未定义一样。

如何让 React 正确检测“insertar”?

最佳答案

这不是你的 php->javascript 变量的问题

React 类(组件)名称应采用驼峰式命名,以大写

开头 所以改变

phpCodeInsertar
对此:
PhpCodeInsertar

关于javascript - React 未捕获类型错误 : Cannot read property 'replace' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28330752/

相关文章:

javascript - 在 javascript 中使用 window.open() 有什么限制吗

javascript - 基于配置值的 Webpack 条件构建

Javascript/Node.js ] 使用 await 处理 promise 的错误

php - Magento 2 : Bulk Actions Not Starting?

JavaScript 性能 : Multiple script blocks Vs single bigger block

php - fatal error : Uncaught Error: Call to undefined function mysql_pconnect()

php - Docker Nginx 连接到私有(private) docker 网络上的 PHP-FPM

javascript - 重构 React.js 代码以提高风格和效率

reactjs - 在 redux-form 中,如何将输入的值限制在一个范围内?

reactjs - Cloudways 服务器中托管的下一个 Js 页面显示 404 错误