jsx

TypeScript and React - children type?

橙三吉。 提交于 2019-12-03 06:29:09
问题 I have a very simple functional component as follows: import * as React from 'react'; export interface AuxProps { children: React.ReactNode } const aux = (props: AuxProps) => props.children; export default aux; And another component: import * as React from "react"; export interface LayoutProps { children: React.ReactNode } const layout = (props: LayoutProps) => ( <Aux> <div>Toolbar, SideDrawer, Backdrop</div> <main> {props.children} </main> <Aux/> ); export default layout; I keep on getting

ReactJS map through Object

眉间皱痕 提交于 2019-12-03 05:04:46
I have a response like this: I want to display the name of each object inside this HTML: {subjects.map((item, i) => ( <li className="travelcompany-input" key={i}> <span className="input-label">{ item.name }</span> </li> ))} But it throws an error of subjects.map is not a function . First, I have to define the keys of the objects where it creates an array of keys, where I want to loop through and show the subject.names . What I also tried is this: {Object.keys(subjects).map((item, i) => ( <li className="travelcompany-input" key={i}> <span className="input-label">key: {i} Name: {subjects[i]}<

React 部分

只愿长相守 提交于 2019-12-03 04:50:26
React 入门和进阶 React介绍 React.js是前端三大新框架:Angular.js、React.js、Vue.js之一,这三大新框架的很多理念是相同的,但是也有各自的特点。 React起源于Facebook的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设Instagram 的网站。做出来以后,发现这套东西很好用,就在2013年5月开源了。 React可以作为一个js库来使用,我们在页面上引用相关的js文件,就可以使用它来做一些页面效果。 React也可以将界面拆分成一个个的组件,通过组件来构建界面,然后用自动化工具来生成单页面(SPA - single page application)应用系统。 React 文档 React使用文档可以通过如下地址查看: http://react.css88.com/docs/getting-started.html 快速开始 首先通过将React作为一个js库来使用,来学习React的一些基本概念,在页面上引入已经下载好的三个js文件,就可以使用React了。 <script src="js/react.development.js"></script> <script src="js/react-dom.development.js"></script> <script

error 'document' is not defined : eslint / React

天大地大妈咪最大 提交于 2019-12-03 04:34:17
I'm building a React app, with create-react-app. I got the following error when running ESLint: 8:3 error 'document' is not defined no-undef. My app runs without error, but I got this ESLint error in 2 files. See one of those .jsx files and my ESLint configuration. index.jsx: import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import './index.css'; ReactDOM.render( <App />, document.getElementById('root'), ); eslintrc.js: module.exports = { "extends": "airbnb", "plugins": [ "react", "jsx-a11y", "import" ], "env": { "jest": true } }; How can I fix this ? For

“Console.log” with Photoshop Scripting - ExtendedScript Toolkit

我与影子孤独终老i 提交于 2019-12-03 04:13:51
I'm doing a bit of Photoshop scripting for the first time and it sure would be great to have a console.log-like function to output array and object values in the Javascript console of the ExtendScript Toolkit App . Is there an equivalent function? Daniel Serodio $.writeln() is what you're looking for. See the JavaScript Tools Guide (PDF) for details. write("any message"); Is what works in XTools for Photoshop. I find that the Photoshop debugger crashes all the time in CS6 on Mac OSX. You can find more about XTools here: http://ps-scripts.sourceforge.net/xtools.html . It's fabulous! I'm using

interface states and props in typescript react

懵懂的女人 提交于 2019-12-03 03:39:26
问题 I'm working on a project that uses typescript as well as react and am new to both. My questions is about interface in typescript and how that relates to props and states. What is actually happening? My application doesnt run at all unless I declare interface props and states, but Im using states through the react constructor function and I've seen examples where all of that information would go into 'interface MyProps' or 'interface MyStates' take this code for example "use strict"; import *

Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to set up my React.js app so that it only renders if a variable I have set is true. The way my render function is set up looks like: render: function() { var text = this.state.submitted ? 'Thank you! Expect a follow up at '+email+' soon!' : 'Enter your email to request early access:'; var style = this.state.submitted ? {"backgroundColor": "rgba(26, 188, 156, 0.4)"} : {}; return ( if(this.state.submitted==false) { Request Invite } ) }, Basically, the important portion here is the if(this.state.submitted==false) portion (I want

React JSX error : Unclosed regular expression

匿名 (未验证) 提交于 2019-12-03 02:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Recently I was facing an i was facing an issue coding React app on Visual Studio code. Because of this issue, whenever I wrote JSX inside the render function of the React Component and saved it, it would go messed up (I mean indentation would get messy). See the pic: This error was also showing error like: 1. Unclosed regular expression How to solve this? 回答1: I tried several options like creating a .eslintrc file or .jshintrc file. But it turned out that in my Visual Studio Code IDE, there was third party extensions(eslint/jslint/tslint

JSX or HTML autocompletion in Visual Studio Code

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there any way to use components or HTML completion in Visual Studio Code? Because typing each letter manually is not good idea when we have classes like Bootstrap etc. For example completion as in Emmet: ul>li*2>a var React = require('react'); var Header = React.createClass({ render: function () { return ( <nav className="navbar navbar-defaullt"> <div className="container-fluid"> <a href="/" className="navbar-brand"> <img width="50" height="50" src="images/logo.png" alt="logo" /> </a> <ul className="nav navbar-nav"> <li><a href="/">Home<

React JSX: selecting “selected” on selected &lt;select&gt; option

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In a React component for a <select> menu, I need to set the selected attribute on the option that reflects the application state. In render() , the optionState is passed from the state owner to the SortMenu component. The option values are passed in as props from JSON. render: function() { var options = [], optionState = this.props.optionState; this.props.options.forEach(function(option) { var selected = (optionState === option.value) ? ' selected' : ''; options.push( <option value={option.value}{selected}>{option.label}</option> ); }); //