为什么此返回状态未定义?

时间:2018-08-08 11:00:38

标签: javascript arrays reactjs jsx

因此,我试图为来自交易所(即)的一系列加密货币数据构建过滤器。 (最低订购数量),但我想按输入内容进行过滤。为了实现这一点,我为state.search编写了一个值作为“测试”,以查看它是否通过。为什么此返回状态未定义?以下是currency.js文件的代码。我正在使用react-static(网站生成器)来构建我的网站,并使用其模板进行自己的调整。

下面是currency.js文件的代码。

import React  from 'react'
import { withRouteData, Link } from 'react-static'

//


export default withRouteData(({ currencies }) => (

  <div>

    <Link to="/markets/quoinex">Quoinex</Link>
        <Link to="/markets/qryptos"><b>Qryptos</b></Link>
        <form>
          <input type="text" name="name" placeholder="BTC etc."/>
          <input className="sub" type="submit" value={this.state.search} />
        </form>

    <h1>Tokens</h1>
    <br />
    <table>
        <tr>
            <th>Crypto/Token</th>
            <th>Min Withdrawal Qty</th>
            <th>Min Order Qty</th>
        </tr>

        {currencies.slice(0,52).map(currency => (
             <tr key={currency.currency}>
             <td>{currency.currency}</td>
             <td>{currency.minimum_withdrawal}</td>
             <td>{currency.minimum_order_quantity}</td> 
         </tr>
      ))}
    </table>
    <table className="table2">
        <tr>
            <th>Crypto/Token</th>
            <th>Min Withdrawal Qty</th>
            <th>Min Order Qty</th>
        </tr>

        {currencies.slice(52,).map(currency => (
             <tr key={currency.currency}>
             <td>{currency.currency}</td>
             <td>{currency.minimum_withdrawal}</td>
             <td>{currency.minimum_order_quantity}</td> 
         </tr>
      ))}
    </table>


  </div>
))

还有static.config.js文件的代码。

import axios from 'axios'
import React, { Component } from 'react'
import { ServerStyleSheet } from 'styled-components'

export default {
  getSiteData: () => ({
    title: 'React Static',
  }),
  getRoutes: async () => {
    const { data: productsquoinex } = await axios.get('https://api.quoine.com/currencies')
    const {data: currencies } = await axios.get('https://api.qryptos.com/currencies')
    return [

      {
        path: '/markets/quoinex',
        component: 'src/containers/Marketsquoinex',
        getData: () => ({
          productsquoinex,
        }),
        children: productsquoinex.map(product => ({
          path: `/product/${product.id}`,
          getData: () => ({
            product,
          }),
        })),
      },
      {
        path: '/markets/qryptos',
        component: 'src/containers/Currencies',
        getData: () => ({
          currencies,
        }),
        children: currencies.map(currency => ({
          path: `/currencies/${currency}`,
          getData: () => ({
            currency,
          }),
        })),
      },
      {
        is404: true,
        component: 'src/containers/404',
      },
    ]
  },
  renderToHtml: (render, Comp, meta) => {
    const sheet = new ServerStyleSheet()
    const html = render(sheet.collectStyles(<Comp />))
    meta.styleTags = sheet.getStyleElement()
    return html
  },
  Document: class CustomHtml extends Component {
    constructor() {
    super();
    this: {
      [x: string]: 'test',
      any:any,
      search: string
    },
  }
    render () {


      const {
        Html, Head, Body, children, renderMeta
      } = this.props


      return (
        <Html>
          <Head>
            <meta charSet="UTF-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1" />
            {renderMeta.styleTags}
          </Head>
          <Body>
          {children}
          </Body>
        </Html>
      )
    }
  },
}

我知道状态的构造函数应该直接在currency.js文件中,但是我不确定该怎么做。 谢谢

0 个答案:

没有答案
相关问题