我正在使用 ReactJS 创建一个组件。
我会看到 html react 在我的控制台上渲染,例如:
import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
class CustomComponent extends React.Component {
render() { return (<div>Custom</div>); }
}
而不是:
ReactDOM.render(<CustomComponent />, document.getElementById('app'));
我会做这样的事情:
console.log(<CustomComponent />);
但是当我在控制台中时,我调用:
babel-node myfile.js
我得到:
如何打印/记录 React 渲染的有效 html 标签?
谢谢。 再见。
最佳答案
使用https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostring
现在您只需打印需要转换为字符串的虚拟 dom 表示形式。
关于javascript - 如何打印/记录reactjs渲染的dom?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34288404/