【问题标题】:Server side React-Redux, Express with no additional ES6 and JSX syntax服务器端 React-Redux,Express,没有额外的 ES6 和 JSX 语法
【发布时间】:2017-11-21 01:24:34
【问题描述】:

我对 react-redux 非常感兴趣,阅读了托管实际应用程序的方法,并提出 Express 中间件是我想做的最好的。 我在尝试弄清楚如何为 react-redux 实现服务器端属性时遇到问题,因为我注意到语法中的部分代码我是新手。

这是服务器端的代码。

import path from 'path'
import Express from 'express'
import React from 'react'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import counterApp from './reducers'
import App from './containers/App'

const app = Express()
const port = 3000

//Serve static files
app.use('/static', Express.static('static'))

// This is fired every time the server side receives a request
app.use(handleRender)

// We are going to fill these out in the sections to follow
function handleRender(req, res) { /* ... */ }
function renderFullPage(html, preloadedState) { /* ... */ }

app.listen(port)

好的,所以我不知道这个带花括号的部分是什么意思:

import { createStore } from 'redux'
import { Provider } from 'react-redux'

是否需要在 React-Redux 的服务器 express 代码中使用 ES6/JSX/Babel 语法?

【问题讨论】:

标签: javascript express react-redux babeljs react-jsx


【解决方案1】:

这与您的代码逻辑无关。这只是从库中导入导出的子模块/函数的一种方式。

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/import

import { createStore } from 'redux'

let createStore = require('redux').createStore

【讨论】:

  • “和一样”---没必要是一样的。可能会,但不保证会。
  • 我应该说“相当于”吗?就是这样。还有什么意思?
  • require('redux').createStore 表示 - “获取默认导出对象并读取其 createStore 属性”。 import { createStore } 表示“使用 createStore 名称进行导入”。不同之处在于,命名的导入不一定属于默认导出的对象,并且不可互换。
  • AFAIK 如果您有一个命名导出,它会在内部转换为默认导出对象中的相同命名条目。
  • 这完全不是真的。 export const foo = 42; export default null; 这里有一个命名导出 foo 等于 42 和一个默认导出 null 根本没有任何属性。
猜你喜欢
  • 2017-06-30
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-09
  • 2016-07-17
  • 1970-01-01
  • 2016-04-22
相关资源
最近更新 更多