jsx

Passing local image uri as props in react-native

半腔热情 提交于 2019-12-13 14:26:28
问题 I'm trying to pass the uri of an image as prop so I can reuse it several times on react-native. However, this current solution prompts me that require should use string literals. const ImageButton = ({ source }) => ( <Image source={require({ source })} /> ); ImageButton.propTypes = { uri: PropTypes.string, }; I've also tried declaring uri as a PropTypes.func, and doing <Image source={{ source }} /> but the image doesn't appear. What's the correct implementation of an image uri prop? 回答1: You

How to validate component composition / “base”-component / rendered root component in React?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 12:13:32
问题 It is common knowledge that when we want to "extend" a <Component> in React, we don't actually extend its class via inheritance, but use composition to render it with custom props inside our "derived" component, like this: class Component extends React.Component { render() { return (<div className={ this.props.special_prop }> I'm a component! </div>); } } class DerivedComponent extends React.Component { render() { return (<Component special_prop='custom value' />); } } So this will create a

Add a component to another component on button click [closed]

不打扰是莪最后的温柔 提交于 2019-12-13 09:25:16
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 months ago . I'm creating a page that if user clicks add more button a text box should be added as many time the user clicks I have created a component where I've created texbox . I've tried to render this component into another component on button click but it is not working. why? class Addmore extends React.Component {

Vue.js的发展史及知识简单梳理

笑着哭i 提交于 2019-12-13 08:44:36
1.学习框架可以主要解决的问题是:高效的将服务器数据渲染到客户端,将用户填写数据高效的反应到视图上。 前端框架时间 backbone angular1.0 2010 React 2013 vue1.0 2014 vue2.0 2016 es6 2016 微信小程序 2016 angular 2016 vue3.0 2019 2020年第一个季度开始全面使用 Vue的认识 vue 1.0 2014 VUE 2.0 2016年 VUE属于轻量级的js框架 MVVM-前端开发 个人开发项目 作者:尤雨溪 使用了VDOM(虚拟DOM) 双向数据绑定:vue.js 则是采用数据劫持结合发布者-订阅者模式的方式,通过Object.defineProperty()来劫持各个属性的setter,getter,在数据变动时发布消息给订阅者,触发相应的监听回调。 jsx语法:JSX就是Javascript和XML结合的一种格式。React发明了JSX,利用HTML语法来创建虚拟DOM。当遇到<,JSX就当HTML解析,遇到{就当JavaScript解析. Vue构成 指令 - 操作VDOM(操作虚拟DOM) 组件系统 - 项目模块化 Vue基础 指令 哪些指令?这个指令的作用 v-if v-for v-model v-bind v-on v-html v-text v-pre

The index of a JS object returns all values in object rather than the actual index

拈花ヽ惹草 提交于 2019-12-13 04:19:50
问题 Let me explain this really quickly, when I fetch data from the database, there's a parent object and inside there is an array of objects, what I'm looking to achieve is to write the correct path so I can access specific items in the db. When receiving the data I store two variables like so: for (let a in obj) { list.push(obj[a]); keys.push(a); } this.setState({ list: list, keys: keys, }); Executing this code will print the following: console.log(this.state.keys[index]);

Putting a variable inside render() return - React Native

我只是一个虾纸丫 提交于 2019-12-13 03:50:43
问题 I am mapping json data and can console.log my result, but I can't insert those values in the render. Here is the code I have for my render: data_use = responseJson; const result_id = data_use.map(function(val) { return val.id; }).join(','); console.log(result_id); render(){ return( <View style = { styles.MainContainer }> <View> <Card> <View> <Text>{result_id}</Text> </View> </Card> </View> </View> ); } The error that I am getting is ReferenceError: result_id is not defined . Which is odd

How to retrieve the key into a Semantic-ui-react dropdown?

。_饼干妹妹 提交于 2019-12-12 20:03:11
问题 I have small question about react dropdown menus. I can extract the values inside the dropdown, but I also need the key, because my page is for selling stuff. So, it is an associative table and I need the id from each table to make my query INNERJOIN . This is how I fill it: let options_customers = []; serviceList[0].map((service, i) => options_customers.push({ key: service.Id, text: service.Name, value: service.Name })) My dropdown: <Dropdown selection options={options_customers} onChange=

PropType is defined but prop is never used

拟墨画扇 提交于 2019-12-12 17:01:07
问题 const propTypes = { prop1: PropTypes.string, prop2: PropTypes.string, prop3: PropTypes.number, }; const something = (props) => ((props.props2 > 0 & props.prop1 === props.props3) ? t('translation/abc') : t('translation/def')); why does the component throw lint error PropType is defined but prop is never used for all three props prop1, prop2, prop3 ? 回答1: This should fix your problem, let's de-structure your props and then assign propTypes to your stateless component. const something = ({prop1,

react.js every nth item add opening tag or closing tag

折月煮酒 提交于 2019-12-12 08:44:49
问题 I'm having trouble with this logic since react/jsx does not allow for non closing tags to be added to an array/child component. For example with bootstrap css I want to add a row for every 4 columns. So the logic is as follows: Add a opening row ex: <div className="row"> , then loop inside this row and every loop append a column ex: <div className="column>{this.data}</div> when the loop reaches 4 check with if(i % 4 == 0) and add a closing </div> tag while adding new row tag <div className=

Embedding the Lighten Css Feature to Jsx/React

爱⌒轻易说出口 提交于 2019-12-12 05:24:34
问题 I currently use the following syntax to embed a state color to jsx. <div className="preview-box" style={{backgroundColor:this.state.color}}> Is there a way to use the lighten feature in css to do something like this? <div className="preview-box" style={{backgroundColor: lighten(this.state.color, 15%)}}> 回答1: You can use SCSS to get backgroundColor: lighten(this.state.color, 15%) css part $awesome-blue: #2196F3; $width: 100%; $height: 500px; .box { background: lighten($awesome-blue, 10%); /*