jsx

import jsx file in tsx compilation error

时光毁灭记忆、已成空白 提交于 2019-12-02 01:07:30
I am trying to import jsx file in tsx file. This is causing the error error TS2604: JSX element type 'Test' does not have any construct or call signatures. I a using webpack , react, typescript, Import tsx files no issues, but any jsx file is causing compilation error, package.json { "name": "typescript-babel-webpack", "version": "1.0.0", "description": "A simple lightweight TypeScript + Babel + Webpack project.", "scripts": { "build": "webpack" }, "license": "", "devDependencies": { "babel-core": "^6.20.0", "babel-loader": "^6.2.9", "babel-plugin-transform-runtime": "^6.15.0", "babel-preset

compiled/minified jsx file is bigger than original file

穿精又带淫゛_ 提交于 2019-12-02 00:07:51
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 is any tool can help me do this. There are a number of settings you can use in Webpack to get your

React 面试问题

北慕城南 提交于 2019-12-01 23:46:52
eact 面试问题 如果你是一位有理想的前端开发人员,并且正在准备面试,那么这篇文章就是为你准备的。本文收集了 React 面试中最常见的 50 大问题,这是一份理想的指南,让你为 React 相关的面试做好充分的准备工作。首先我们快速了解一下 React 在市场上的需求和现状,然后再开始讨论 React 面试问题。 JavaScript 工具的市场地位正在缓慢而稳定地上升当中,而对 React 认证的需求正在飞速增长。选择正确的技术来开发应用程序或网站变得愈加艰难。React 被认为是 Javascript 语言中增长最快的框架。 虚拟 DOM 和可复用部件等独特特性吸引了前端开发人员的注意。尽管成熟的框架(如 Angular、Meteor 和 Vue 等)在 MVC(模型 - 视图 - 控制器)中只是一个“视图”库,但它们都有很强的竞争力。下图显示了常见 JS 框架的趋势: 以下是面试官最有可能提出的 50 个面试问题和答案。 React 面试问题——常规知识 真实 DOM 和虚拟 DOM 的区别 真实 DOM 虚拟 DOM 1.更新较慢 1.更新较快 2.可以直接更新 HTML 2.不能直接更新 HTML 3.元素更新时创建一个新 DOM 3.元素更新时更新 JSX 4.DOM 操作开销较大 4.DOM 操作非常容易 5.内存浪费严重 5.没有内存浪费 什么是 React?

Undefined is not a function near _reactNavigation.StackNavigator

北城以北 提交于 2019-12-01 22:54:14
问题 I want to setup a React Native app with a side menu and a tab menu at the same time. I was following this tutorial. My code. I get the error: undefined is not a function (near '...(0 , _reactNavigation.TabNavigator)...') Which you can see here: Preview of some of the files: App.js import React from 'react'; import { Drawer } from './src/navigators'; export default class App extends React.Component { render() { return ( <Drawer /> ); } } navigators.js import React, { Component } from 'react';

JSX doesn't evaluate integer in expression as boolean

允我心安 提交于 2019-12-01 21:00:53
I'm used to write render optional Components like this: var Foo = React.createClass({ render: function() { var length = 0; return <div>Foo {length && <Bar />}</div>; } }); This shorthand if is mentioned in the if/else in JSX guide as immediately-invoked function expression. However, since my latest update of React, it started to render 0 instead of null . Here is a jsfiddle Why is that happening? The && operator evaluates the left-hand expression first, and if the left-hand expression evaluates to something falsy it returns the value of the left-hand expression without evaluating further. So

Returning multiple elements in JSX

此生再无相见时 提交于 2019-12-01 17:25:26
I'm trying to return two links if the user is not logged in. Something like this: <Nav> {if(this.state.user) { <NavItem onClick={this.logout}>Log out</NavItem> } else { <NavItem onClick={this.login}>Log in</NavItem> <NavItem onClick={this.register}>Register</NavItem> } } </Nav> I know I can do this with a ternary operator: <Nav> {this.state.user ? <NavItem onClick={this.logout}>Log out</NavItem> : <NavItem onClick={this.login}>Log in</NavItem> } </Nav> The problem is I want to render the two NavItems. I saw I can do it with a function, but when I try to do it in a function like this:

Accessing `this` in react when assigning method to an event

做~自己de王妃 提交于 2019-12-01 13:47:35
Apologize in advance, I am very new to React. In printDocument I am setting the oHiddFrame.onload = this.setPrint; even to this.setPrint but am getting an error of Cannot set property '__container__' of undefined for this in setPrint on the first assignment. I am setting onClick={this.printDocument.bind(null, this.props.document.view_href)} on button in render(). How do I bind "this" to the actual event I'm assigning it to? Much appreciate any help or advise. closePrint: function () { document.body.removeChild(this.oHiddFrame.__container__); }, setPrint: function () { this.contentWindow._

Accessing `this` in react when assigning method to an event

一世执手 提交于 2019-12-01 12:08:44
问题 Apologize in advance, I am very new to React. In printDocument I am setting the oHiddFrame.onload = this.setPrint; even to this.setPrint but am getting an error of Cannot set property '__container__' of undefined for this in setPrint on the first assignment. I am setting onClick={this.printDocument.bind(null, this.props.document.view_href)} on button in render(). How do I bind "this" to the actual event I'm assigning it to? Much appreciate any help or advise. closePrint: function () {

React入门学习

﹥>﹥吖頭↗ 提交于 2019-12-01 10:33:21
为了获得更好的阅读体验,请访问原地址: 传送门 一、React 简介 React 是什么 React 是一个起源于 Facebook 的内部项目,因为当时 Facebook 对于市场上所有的 JavaScript MVC 框架都不太满意,所以索性就自己写了一套,用来架设 Instagram。做出来之后,发现这套东西还蛮好用的,于是就在 2013 年 5 月开源了 。 在这里我们需要稍微注意一下 库(Library) 和 框架(Framework) 的区别, React 本身是一个用于构建用户界面的 JavaScript 库 ,而我们平时所说的 React 框架其实是指的是 React/ React-router 和 React-redux 的结合体,库和框架的本质区别体现在于控制权: 「库」是一个封装好的特定的集合,提供给开发者使用,而且是特定于某一方面的集合(方法和函数),库没有控制权,控制权完全在于使用者本身; 「框架」顾名思义是一套架构,会基于自身的特点向用户提供一套比较完整的解决方案,如果使用者选定了一套框架,那么就需要根据框架本身做出一定的适应。 为什么使用 React? 这是一个非常有趣的问题,也让我困惑和苦恼。在笔者还在学校的时候尝试用 Vue 搭建了一套简单的博客系统,学习曲线平滑,让只会一些基础 HTML/ CSS 代码的我通过一段时间学习就能够上手了,但是学习

Delay array map iteration in React

余生长醉 提交于 2019-12-01 09:13:29
I have this array, that I want to iterate. I need to delay it by a couple of seconds before the next. {this.props.things.map((thing, index) => { return ( <div key={index}>{thing.content}</div> // Delay 1 second here ) })} The initial state of this array is always more than one. For UI purposes I want them to load in one by one in to the DOM. The render function of react is synchronous. Also javascript map is synchronous. So using timers is not the right solution here. You can however, in your component state, keep track of items that have been rendered and update that state using javascript