简体   繁体   English

带有redux和react的webpack-dev-server阻止了我的输入

[英]webpack-dev-server with redux and react is blocking my inputs

The app is accessible on this URL: http://91.142.210.160:3000/webpack-dev-server/ 可通过以下URL访问该应用程序:http: //91.142.210.160 : 3000/webpack-dev-server/

As you can see, the app works without errors but I can't really click on the text input and add a todo. 如您所见,该应用程序可以正常运行,但是我无法真正点击文本输入并添加待办事项。

Bellow I'll show you my files, if you need more just write it down in the comments. 在下面,我将向您显示我的文件,如果需要更多,请在注释中写下。

// app.js // app.js

 import React from 'react'; import { render } from 'react-dom'; import { createStore } from 'redux'; import { Provider } from 'react-redux'; import reducer from './reducer'; import { TodoList } from './containers'; // ^^^^^^^^^^ const store = createStore(reducer); render( <Provider store={store}> <TodoList /> </Provider>, document.getElementById('app') ); 

// Components.js // Components.js

 import React from 'react'; export function Todo(props) { const { todo } = props; if(todo.isDone) { return <strike>{todo.text}</strike>; } else { return <span>{todo.text}</span>; } } export function TodoList(props) { const { todos, toggleTodo, addTodo } = props; const onSubmit = (event) => { const input = event.target; console.log("input", input); const text = input.value; const isEnterKey = (event.which == 13); const isLongEnough = text.length > 0; if(isEnterKey && isLongEnough) { input.value = ''; addTodo(text); } }; const toggleClick = id => event => toggleTodo(id); return ( <div className='todo'> <input type='text' className='todo__entry' placeholder='Add todo' onKeyDown={onSubmit} /> <ul className='todo__list'> {todos.map(t => ( <li key={t.get('id')} className='todo__item' onClick={toggleClick(t.get('id'))}> <Todo todo={t.toJS()} /> </li> ))} </ul> </div> ); } 

// containers.js // container.js

 import { connect } from 'react-redux'; import * as components from './components'; import { addTodo, toggleTodo } from './actions'; export const TodoList = connect( function mapStateToProps(state) { return { todos: state }; }, function mapDispatchToProps(dispatch) { return { addTodo: text => dispatch(addTodo(text)), toggleTodo: id => dispatch(toggleTodo(id)) }; } )(components.TodoList); 

// actions.js // actions.js

 const uid = () => Math.random().toString(34).slice(2); export function addTodo(text) { return { type: 'ADD_TODO', payload: { id: uid(), isDone: false, text: text } }; } export function toggleTodo(id) { return { type: 'TOGGLE_TODO', payload: id } } 

// reducer.js // reducer.js

 import { List, Map } from 'immutable'; const init = List([]); export default function(todos=init, action) { switch(action.type) { case 'ADD_TODO': return todos.push(Map(action.payload)); case 'TOGGLE_TODO': return todos.map(t => { if(t.get('id') === action.payload) { return t.update('isDone', isDone => !isDone); } else { return t; } }); default: return todos; } } 

Not really sure if it's programming related or my browser config that is too strict about iframes 不确定是与编程相关还是对iframe过于严格的浏览器配置

Edit 1: I started the dev server with the following command: 编辑1:我使用以下命令启动了开发服务器:

webpack-dev-server --port 3000 --hot --host 0.0.0.0 webpack-dev-server --port 3000 --hot --host 0.0.0.0

And this is my webpack.config.js 这是我的webpack.config.js

 module.exports = { entry: './src/app.js', output: { path: __dirname, filename: 'bundle.js' }, devtool: 'source-map', module: { loaders: [ { test: /\\.js$/, exclude: /node_modules/, loader: 'babel', query: { presets: [ 'es2015', 'react' ] } } ] } }; 

You're using the wrong url. 您使用的网址错误。 If you access your app with http://91.142.210.160:3000/ it works perfectly fine. 如果您使用http://91.142.210.160:3000/访问您的应用,则可以正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM