jsx

Arrow vs classic method in ES6 class

情到浓时终转凉″ 提交于 2020-01-26 20:13:52
问题 Is there any reason to write classic syntax of ES6 methods? class MyClass { myMethod() { this.myVariable++; } } When I use myMethod() as callback on some event, I must write something like this (in JSX): // Anonymous function. onClick={() => { this.myMethod(); }} // Or bind this. onClick={this.myMethod.bind(this)} But if I declare method as arrow function: class MyClass { myMethod = () => { this.myVariable++; } } than I can write just (in JSX): onClick={this.myMethod} 回答1: The feature you are

Illustrator ExtendScript set FILL opacity of selection

白昼怎懂夜的黑 提交于 2020-01-24 10:23:05
问题 Is there any way to access a pathItem's fill opacity with javascript? I can access the overall opacity, but I want to lower the opacity of the fill while keeping the stroke fully opaque. I can't find anything in the documentation, nor can I find anyone else asking this question. I can set the overall opacity like so: var selection = app.activeDocument.selection; selection[0].opacity = 50; I've tried every variant of " fillOpacity " that I can think of, like this: var selection = app

How to update parent's state?

≡放荡痞女 提交于 2020-01-23 17:58:26
问题 I am new to react and trying to update parent's state but no luck so far. Component class InputBox extends Component { constructor(props) { super(props); this.type = props.type; } render() { return ( <div> <input type={this.type}/> </div> ); } } Other container where I want to use this component to toggle password constructor(props) { super(props); this.state = { type: 'password', wording: 'Show', }; this.changeState = this.changeState.bind(this); } changeState() { const oldState = this.state

VScode配置prettier和eslint

拈花ヽ惹草 提交于 2020-01-22 18:11:56
前端工具中如果使用prettier进行代码格式化,eslint进行错误检测。对前端工作有极大的帮助 原则: prettier和eslint配置可以分成两种,一种是本地配置,一种是全局配置。VScode会检测文件夹根目录下有没有用户自定义的配置文件 .prettierrc.json和.eslintrc.js。如果有则会优先加载用户自定义的配置,如果没有则会加载VScode中的setting.json配置文件内的配置。 现在vscode安装prettier和eslint的插件,装使用人数最多的就行。注意的是,这个只是插件哦,在本地使用npm安装prettier和eslint .prettierrc.json文件配置: { "tabWidth" : 2 , "vetur.format.defaultFormatter.html" : "prettier" , "singleQuote" : true , "semi" : false } .eslintrc.js文件配置: module . exports = { root : true , parserOptions : { ecmaVersion : 6 , sourceType : 'module' , ecmaFeatures : { jsx : true , globalReturn : true , impliedStrict

React, how to access the DOM element in my render function from the same component

主宰稳场 提交于 2020-01-22 17:05:46
问题 I'm wondering what's the best practice for accessing the DOM elements inside my render function from the same component. Note that I will be rendering this component multiple times on a page. e.g. var TodoItem = React.createClass({ ... render:function(){ function oneSecLater(){ setTimeout(function(){ //select the current className? this doesn't work, but it gives you an idea what I want. document.getElementsByClassName('name').style.backgroundColor = "red"; )}, 1000); } return( <div className

How to pass string and component as prop?

江枫思渺然 提交于 2020-01-21 16:36:48
问题 I can pass something like this fine: <CardTitle title={this.props.post.title} subtitle={ <Link to={this.props.post.author}>{this.props.post.author}</Link> } /> But I need to pass both a component and some string text, but doing this doesn't work: <CardTitle title={this.props.post.title} subtitle={(` This is a link: ${<Link to={this.props.post.author}>{this.props.post.author}</Link>} `)} /> What's the right syntax for this? 回答1: Try passing it as a React Element altogether, not as a string:

How to pass string and component as prop?

独自空忆成欢 提交于 2020-01-21 16:36:13
问题 I can pass something like this fine: <CardTitle title={this.props.post.title} subtitle={ <Link to={this.props.post.author}>{this.props.post.author}</Link> } /> But I need to pass both a component and some string text, but doing this doesn't work: <CardTitle title={this.props.post.title} subtitle={(` This is a link: ${<Link to={this.props.post.author}>{this.props.post.author}</Link>} `)} /> What's the right syntax for this? 回答1: Try passing it as a React Element altogether, not as a string:

compiled/minified jsx file is bigger than original file

这一生的挚爱 提交于 2020-01-21 12:21:28
问题 The original jsx file size is 189k after removing all spaces. The compiled/minified file size js is 217k without any dependencies. I have used all webpack/babel optimization to minify code size except treeshaking. I am planning to shorten member variable/function name to reduce file size, because js-minify can only handle local variable names, e.g. replace react's createElement with shorter name. I just manually tried, file size is reduced by 9k after createElement removed. Not sure if there

react - JSX踩坑记

走远了吗. 提交于 2020-01-19 02:31:12
1、在 JSX 中,注释的写法: NO1 < Fragment > { /* 正确注释的写法 */ } < div > < input value = { this.state.inputValue } onChange = { this.inputChange.bind ( this ) } / > < button onClick = { this.addList.bind ( this ) } > 增加服务 < /button > < /div > NO2 < Fragment > { //正确注释的写法 } < div > < input value = { this.state.inputValue } onChange = { this.inputChange.bind ( this ) } / > < button onClick = { this.addList.bind ( this ) } > 增加服务 < /button > < /div > 2、 html 标签上的 class 需写为 className ,否则控制台会出现警告 3、JSX 中的 HTML 解析问题 如果想在文本框里输入一个 h1 标签,并进行渲染。默认是不会生效的,可以使用 dangerouslySetInnerHtml 属性 解决,代码如下: < ul > { this.state

react(4)在jsx中书写js代码

风格不统一 提交于 2020-01-18 03:22:55
import React from 'react' import ReactDOM from 'react-dom' let a = 10 let str = 'Hello world' let boo = false let title = '123' const h1 = <h1>456</h1> const arr = [ <h2>h2</h2>, <h3>h3</h3> ] const arrStr = ['a', 'b', 'c', 'd'] // 没意义之后的修改 // 方案一:定义一个空数组,用来存放名称和标签 // react 中,需要把key添加给被forEach或map或for循环直接控制的元素 const nameArr = [] arrStr.forEach(item => { const temp = <h5 key={item}>{item}</h5> nameArr.push(temp) }) // 方案二:数组的map方法 // const result = arrStr.map(item =>{ // return item + ',' // }) // 当我们需要在jsx控制的区域内写js表达式时需要把js代码写到{}中 ReactDOM.render(<div> {a +2} {str} {boo ? '1' : '2'} <p title =