Tag: jsx

React Native – 图片需要使用dynamic名称的模块

我目前正在使用React Native构build一个testing应用程序。 Image模块到目前为止一直工作正常。 例如,如果我有一个名为avatar的图像,下面的代码片段工作正常。 <Image source={require('image!avatar')} /> 但是,如果我将其更改为dynamicstring,我会得到 <Image source={require('image!' + 'avatar')} /> 我得到的错误: 要求未知模块“image!avatar”。 如果您确定模块在那里,请尝试重新启动打包程序。 显然这是一个人为的例子,但dynamic的图像名称是重要的。 React Native不支持dynamic图像名称吗?

应用className / onClick / onChange在自定义React组件上不起作用

我几乎是新的react 。 我正在尝试创build一个简单的编辑和创build蒙版。 这里是代码: import React, { Component } from 'react'; import Company from './Company'; class CompanyList extends Component { constructor(props) { super(props); this.state = { search: '', companies: props.companies }; } updateSearch(event) { this.setState({ search: event.target.value.substr(0,20) }) } addCompany(event) { event.preventDefault(); let nummer = this.refs.nummer.value; let bezeichnung = this.refs.bezeichnung.value; let id = Math.floor((Math.random()*100) + […]

为什么不应该使用箭头函数或绑定?

我正在使用我的React应用程序运行lint,并收到此错误消息: error JSX props should not use arrow functions react/jsx-no-bind 这就是我正在运行箭头函数(在onClick ): {this.state.photos.map(tile => ( <span key={tile.img}> <Checkbox defaultChecked={tile.checked} onCheck={() => this.selectPicture(tile)} style={{position: 'absolute', zIndex: 99, padding: 5, backgroundColor: 'rgba(255, 255, 255, 0.72)'}} /> <GridTile title={tile.title} subtitle={<span>by <b>{tile.author}</b></span>} actionIcon={<IconButton onClick={() => this.handleDelete(tile)}><Delete color="white"/></IconButton>} > <img onClick={() => this.handleOpen(tile.img)} src={tile.img} style={{cursor: 'pointer'}}/> </GridTile> </span> ))} 这是一个不好的做法,应该避免? […]