小编Sac*_*ria的帖子

react-stripe-elements 错误:您必须提供条纹元素或有效的令牌类型才能创建令牌

我正在使用 react-stripe-elements 创建一个用于支付的令牌。但是,根据文档,当卡片形式包含在 Elements 组件中时,它应该自动选择要标记化的条纹元素。

但是,在这种情况下,我们会遇到错误

You must provide a Stripe Element or a valid token type to create a Token.
Run Code Online (Sandbox Code Playgroud)

这是代码:

import React from 'react';
import {CardCVCElement, CardExpiryElement, CardNumberElement, PostalCodeElement, StripeProvider, Elements} from 'react-stripe-elements';

class CheckoutForm extends React.Component {
  constructor(props) {
    super(props);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleSubmit(ev) {
    ev.preventDefault();

    this.props.stripe.createToken({email: 'test@test.com'}).then(({token }) => {console.log('Received Stripe token:', token)});
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          Card details
          <CardNumberElement />
          <CardExpiryElement />
          <CardCVCElement />
          <PostalCodeElement />
        </label>
        <button>Confirm order</button>
      </form> …
Run Code Online (Sandbox Code Playgroud)

javascript stripe-payments reactjs stripe.js react-stripe-elements

7
推荐指数
1
解决办法
9702
查看次数

未定义的局部变量或方法`flash'for#<Devise :: OmniauthCallbacksController:0x007fb5d1741e48>

我正在使用Omniauth-facebook和Devise-token-auth构建一个Rails-API,其中Angular和ng-token-auth用于前端.但是当用facebook登录时,我会看到错误:

undefined local variable or method `flash' for #<Devise::OmniauthCallbacksController:0x007fd027a51e10>
Run Code Online (Sandbox Code Playgroud)

似乎omniauth自动使用闪存中间件但是rails-api不包括这个,并且我没有成功禁用使用omniauth的flash.我的配置如下:

application.rb中:

    require File.expand_path('../boot', __FILE__)

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module PathfinderApi
  class Application < Rails::Application
    config.active_record.raise_in_transactional_callbacks = true


    config.middleware.insert_before 0, "Rack::Cors" do
      allow do
        origins '*'
        resource '*', :headers => :any, …
Run Code Online (Sandbox Code Playgroud)

middleware ruby-on-rails devise rails-api omniauth-facebook

6
推荐指数
1
解决办法
3570
查看次数

根据单独的对象键、值过滤对象数组

我有以下一组人:

  const FIRST_ARRAY = [
    {
      name: 'Simon',
      age: 32,
      occupation: 'Student'
    },
    {
      name: 'Vera',
      age: 22,
      occupation: 'Developer'
    }
  ];
Run Code Online (Sandbox Code Playgroud)

我想过滤数组以生成基于“过滤器”对象的单独数组。

例如,如果我的过滤器是:

  const FILTERS = {
    age: 32,
    name: 'John',
    occupation: ''
  };
Run Code Online (Sandbox Code Playgroud)

新数组应该为空,因为数组中没有人拥有 32 和 John 的组合。但是,如果我的过滤器是:

 const FILTERS = {
    age: 32,
    name: 'Simon',
    occupation: ''
  }
Run Code Online (Sandbox Code Playgroud)

返回的新人员数组将是:

 const NEW_ARRAY = [
    {
      name: 'Simon',
      age: 32,
      occupation: 'Student'
    }
  ];
Run Code Online (Sandbox Code Playgroud)

如何通过迭代“过滤器”对象值来过滤人员数组?请记住,过滤器键和值会一直动态变化。

javascript arrays object filter javascript-objects

2
推荐指数
1
解决办法
3511
查看次数

使用Webpack,SASS和React在'main.scss'上报错'找不到模块'

当尝试设置SCSS以使用Webpack在我的React应用程序上运行样式时,出现以下错误:

Module not found: Error: Can't resolve 'style' in '/Users/sachinkaria/Workspace/GC' @ ./app/index.js 4:0-29 @ multi ./app/index.js'
Run Code Online (Sandbox Code Playgroud)

并在浏览器中:

Uncaught Error: Cannot find module "/styles/main.scss"
Run Code Online (Sandbox Code Playgroud)

我的webpack.config.js配置如下:

var HtmlWebpackPlugin = require('html-webpack-plugin');-
var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
  template: __dirname + '/app/index.html',
  filename: 'index.html',
  inject: 'body'
});

module.exports = {
  entry: [
    './app/index.js'
  ],
  output: {
    path: __dirname + '/dist',
    filename: "index_bundle.js"
  },
  module: {
    loaders: [
      {test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"},{
            test: /\.scss$/,
            loaders: ['style', 'css', 'sass']
        }
    ]
  },
  plugins: [HTMLWebpackPluginConfig]
}; …
Run Code Online (Sandbox Code Playgroud)

sass reactjs webpack webpack-dev-server sass-loader

1
推荐指数
1
解决办法
9366
查看次数

更新redux状态数组中的对象而不是重新渲染反应组件

我想在我的redux状态下更新chefs数组中的一位厨师.该数组的一个例子如下:

  [
    { _id: 1, name: 'first chef' },
    { _id: 2, name: 'second chef' },
    { _id: 2, name: 'third chef' }
  ]
Run Code Online (Sandbox Code Playgroud)

我调用了API,然后返回更新的chef对象.我基本上在当前状态下找到相关的厨师对象,但是,当我不可更新地更新它时,我的反应组件不会重新渲染.

这是更新redux reducer中对象数组中单个对象的正确方法吗?

import _ from 'lodash';
import { ADMIN_LIST_CHEFS, ADMIN_GET_CHEF, UPDATE_CHEF_LIST } from '../actions/types';

const INITIAL_STATE = { chefs: [], chef: null };
let CHEFS = [];
let INDEX = null;

export default function (state = INITIAL_STATE, action) {
  switch (action.type) {
    case UPDATE_CHEF_LIST:
      CHEFS = state.chefs;
      INDEX = _.findIndex(CHEFS, (chef => chef._id === action.id)); …
Run Code Online (Sandbox Code Playgroud)

immutability reducers redux react-redux

0
推荐指数
1
解决办法
2280
查看次数