是否可以在eslint中停用此错误?
Parsing error: 'import' and 'export' may only appear at the top level
Run Code Online (Sandbox Code Playgroud) 我也正在尝试将 React Native 应用程序转变为 React Native Web 应用程序。
我想做以下类型的导入:
if (Platform.OS !== 'web') {
import { Route, Link, Switch, push, DeepLinking } from "react-router-native";
}
Run Code Online (Sandbox Code Playgroud)
但是我收到错误:
Syntax error: 'import' and 'export' may only appear at the top level (16:4)
Run Code Online (Sandbox Code Playgroud)
现在我尝试在 package.json 中添加 ESLint 配置来防止出现这种情况:
"eslintConfig": {
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": true
}
}
Run Code Online (Sandbox Code Playgroud)
但它仍然在发生。
如何允许动态导入?
我收到此错误:this.props.postBooks不是函数。
我有一个动作-postBooks-我正尝试通过道具发送。
这是我的组件:
"use strict"
import React from 'react'
import {Well,Panel,FormControl,FormGroup,ControlLabel,Button} from 'react-bootstrap'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import {postBooks} from '../../actions/booksActions'
import {findDOMNode} from 'react-dom'
export class BooksForm extends React.Component{
handleSubmit(){
const book = [{
title: findDOMNode(this.refs.title).value,
description: findDOMNode(this.refs.description).value,
price: findDOMNode(this.refs.price).value
}]
this.props.postBooks(book)
}
render(){
return(
<Well>
<Panel>
<FormGroup controlId='title'>
<ControlLabel> Title </ControlLabel>
<FormControl
type='text'
placeholder='Enter Title'
ref='title' />
</FormGroup>
<FormGroup controlId='description'>
<ControlLabel> Enter Description </ControlLabel>
<FormControl
type='text'
placeholder='Enter Description'
ref='description' />
</FormGroup>
<FormGroup controlId='price'>
<ControlLabel> …Run Code Online (Sandbox Code Playgroud)