草庐IT

react-native-implementation

全部标签

javascript - 获取 JSON 并遍历 react-native 中的值

我是ReactNative的新手,我试图简单地遍历一个示例json文件,但收到错误undefinedisnotafunction(evaluating'this.state.results.map')我最初将状态设置为一个对象,所以不确定为什么会收到此错误。这是JS:importReact,{Component}from'react';import{AppRegistry,ListView,Text,View,StyleSheet,TouchableHighlight}from'react-native';varREQUEST_URL='https://facebook.github.

javascript - 尝试登录时出现 React-native、Firebase 网络错误

我遵循了使用Firebase的React-native登录教程,我使用create-react-native-app为了方便开发(我的package.json),我使用的是NodeJSv6.10.1,我使用的是Note4Device(4.4.4),我启用了Email/Password在Firebase控制台中进行身份验证,出于某种原因我得到:{code:"auth/network-request-failed",message:"Anetworkerror(suchastimeout,interruptedconnectionorunreachablehost)hasoccurred.

javascript - react-i18next: 在文本中间插入 HTML 标签中的链接

我正在使用react,i18next和react-i18next.我想在文本中间有一些带有HTML链接的可翻译文本,这些文本是在react中插入的,如下所示:Thisismytextwithabeautifullinkinthemiddleofthetext下面的解决方案有效,但问题是我需要在react中插入链接,因此它不能在标签文件中进行硬编码:"my-label":"Thisismytextwithabeautifullinkinthemiddleofthetext"[...]看起来这样好多了:"my-label":"Thisismytextwith{{link}}inthemid

javascript - React 中的构造方法

我已阅读ReactDocs关于构造函数方法及其在设置状态和绑定(bind)函数方面的用途,但在大多数情况下真的有必要吗?做和做有什么区别exportdefaultclassMyClassextendsComponent{constructor(props){super(props);this.state={foo:'bar',};this.member='member';this.someFunction=this.anotherFunction(num);}anotherFunction=(num)=>num*2;render(){//renderjsxhere}}然后简单地将所有这

javascript - 在 React 中的现有状态转换错误期间无法更新

在我的渲染return()中,我有这些:Today这是什么函数:selectTimeframe(timeframe){//this.setState({timeframe});}^我现在必须注释掉setState否则我会收到我在上面发布的错误并且应用程序中断。我的构造函数中有这个:this.selectTimeframe=this.selectTimeframe.bind(this);我找到了这个answerhere,但这没有意义,我应该如何传递变量?或者他是说每个独特的按钮都需要独特的功能?至于避免在渲染内部调用它?完整代码importReactfrom'react';exportc

javascript - react 导入根路径助手

在react中因为我必须导入不同的助手或组件我遇到了这个问题importapproxPerDayfrom'../../../utils/approxPerDay.js'importotherstufffrom'../components/otherstuff'在另一个文件中它可能是importapproxPerDayfrom'../utils/approxPerDay.js'找到相对路径真的很费时间。有没有npm或helper可以解决这个问题? 最佳答案 我遇到了类似的问题。我终于按照这篇文章解决了它:https://medium.

javascript - React Router v4 将通过状态从搜索重定向到结果

有一个搜索组件,当有效负载返回时重定向到结果组件。希望该结果组件使用ReactRouterv4Redirect显示通过的搜索状态.我在文档中的假设是使用state:{referrer:currentLocation}可以传递一个对象。搜索exportdefaultclassSearchextendsComponent{constructor(props){super(props);this.state={searchValue:'',results:[]}this.handleKeyPress=this.handleKeyPress.bind(this);}handleKeyPress

javascript - 使用 Redux、React 和 react-router-dom 4.x 时从动态组件获取 ref

我有以下类(class)classMatchBoxextendsReact.Component{constructor(props){super(props);this.countdownHandler=null;this.showBlocker=true;this.start=this.start.bind(this);}start(){...}render(){...return(...);}};functionmapStateToProps(state){...}functionmatchDispatchToProps(dispatch){...}exportdefaultwit

javascript - 如何使用 TypeScript 将拖动事件处理程序附加到 React 组件

我正在使用TypeScript(2.4.2)首次涉足React(15.6.1),我正在尝试创建一个组件来表示可拖动的JSON字段。这是我的组件代码:import*asReactfrom"react";interfaceJsonFieldProps{name:string;type:string;indent:number;}exportclassJsonFieldextendsReact.Component{marginStyle={'text-indent':`${this.props.indent*15}px`};render(){return{this.props.name}:{

javascript - 使用 Apollo React 使用 GraphQL 包装 REST api

我需要使用Apollo客户端和React做一个项目(货币兑换应用程序)。我需要用graphql包装现有的RESTapi(fixer.io)。到目前为止,没有运气在网上找到解决方案。尝试了几个教程,但它们似乎不起作用。有人有这方面的经验吗?谢谢。 最佳答案 我假设你使用Apolloclient2.0并希望一切都在客户端。首先你需要一个apollobridgelink.它用于“当您(还)没有GraphQL服务器并且想在客户端上使用GraphQL时”。它的源代码很短,所以你可以内联它:/*Copyright(c)2017DavidCize