Reactjs 升华和反应
我是新手,我正在阅读教程,这是我正在编写的代码:Reactjs 升华和反应,reactjs,sublimetext3,Reactjs,Sublimetext3,我是新手,我正在阅读教程,这是我正在编写的代码: import React from 'react' export default class App extends React.Component { render() { const person = { firstName: 'John', lastName: 'Doe' }; function formatName(
import React from 'react'
export default class App extends React.Component {
render() {
const person = {
firstName: 'John',
lastName: 'Doe'
};
function formatName(user) {
return user.firstName + ' ' + user.lastName;
}
function formatDate(date) {
return date.toLocaleDateString();
}
function getGreeting(user) {
if(user) {
return <h1>Hello, {formatName(user)}!</h1>;
}
return <h1>Hello, Stranger.</h1>;
}
function tick() {
const element = (
<div>
<h1>Hello, world!</h1>
<h2>It is {new Date().toLocaleTimeString()}.</h2>
</div>
);
}
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
function App() {
return (
<div>
<Welcome name='Sara'/>
<Welcome name='Cahal'/>
<Welcome name='Edite'/>
</div>
);
}
// other code...
const hi = <h1>{getGreeting(person)}</h1>;
return (hi);
}
}
从“React”导入React
导出默认类App扩展React.Component{
render(){
const person={
名字:“约翰”,
姓:“Doe”
};
函数formatName(用户){
返回user.firstName+“”+user.lastName;
}
函数格式日期(日期){
返回日期。toLocaleDateString();
}
函数getGreeting(用户){
如果(用户){
返回Hello,{formatName(user)}!;
}
你好,陌生人。;
}
函数tick(){
常量元素=(
你好,世界!
它是{new Date().toLocaleTimeString()}。
);
}
功能欢迎(道具){
返回Hello,{props.name};
}
函数App(){
返回(
);
}
//其他代码。。。
const hi={getGreeting(person)};
返回(hi);
}
}
我是这样看待代码的:
为什么颜色是这种形式?这样的代码很难读懂。
我怎样才能看到教程中的颜色?
我错在哪里?有没有办法将React设置为language?您需要使用babel插件来实现Sublime。它将为您提供es6和jsx语法高亮显示。只需遵循他们的文档,在默认情况下为您的
.js
和.jsx
文件启用它
干杯 选中此链接,因为您已经粘贴了React to Sublime Text的教程/文档中的代码,Sublime Text会因为主题(默认主题:monokai)而向您显示上述代码。您可以在中查找各种其他主题。ST还支持许多特定于react的软件包,例如@Think Tworth I Readed this article,但它对我没有帮助。@the DarkKnight I安装了react JS软件包,但它是相同的。。