React is a headache to learn, and many concepts don't seem to be clear.

Family bucket

    "react": "^16.2.0",
    "react-dev-utils": "^5.0.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.7",
    "react-router-dom": "^4.2.2",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",

what is all this?

Vue is much more friendly, and most of them can get started with a tutorial.

< H2 > status Management < / H2 >

Vue has officially assigned four operations, and the data storage and operation are clear at a glance.
then learn react now and follow a tutorial

import axios from "axios";
import {getRedirectPath} from "../util.js";

const REGISTER_SUCCESS = "REGISTER_SUCCESS"
const ERROR_MSG = "ERROR_MSG"

const initState = {
  redirectTo: "",
  isAuth: false,
  msg: "",
  user: "",
  pwd: "",
  type: "",
}


// reducer
export function user(state = initState, action) {
  switch(action.type) {
    case REGISTER_SUCCESS:
      return {...state, msg:"",redirectTo:getRedirectPath(action.payload) , isAuth:true, ...action.payload}
    case ERROR_MSG:
      return {...state, isAuth:false, msg:action.msg}
    default:
      return state
  }
}

function registerSuccess(data) {
  return {type:REGISTER_SUCCESS,payload:data}
}

function errorMsg(msg) {
  return {msg, type:ERROR_MSG}
}

export function regisger({user, pwd, repeatpwd, type}) {
  if (!user || !pwd || !type) {
    return errorMsg("")
  } else if (pwd !== repeatpwd) {
    return errorMsg("")
  }
  return dispatch => {
    axios.post("/user/register", { user, pwd, type }).then(res => {
      if (res.status === 200 && res.data.code === 0) {
        dispatch(registerSuccess({user,pwd,type}))
      } else {
        dispatch(errorMsg(res.data.msg))
      }
    })
  }
}

what on earth is dispatch doing?

< H2 > component passes values < / H2 >

Vue: parent to child : child component data name = "parent component data name"
event name passed by the child to the parent @ child component = "event name defined by the parent component" this.$emit ("event name passed by the child component", data)
react: this.props.history.push ("/ register") what is stored in this props? Why is there a history function and a string like this.props.msg ?

The

tutorial introduces so many plug-ins what do the imported functions in each plug-in do?
you tell me that this function of the plug-in is used here, but what exactly does it do? What problem do you want to solve?

Vue something a code explains clearly, react wants to write notes do not know where to start, a smell of strong coupling
now I always feel that there is something missing, the concept does not seem to be clear. Do you have any suggestions?


although I have chosen the best answer, I have just seen it and come back to it, which is not only a different point of view, but also a summary of myself.

first of all, I moved from react to vue, and the intoxicated point is that react is harder than vue, but react is more powerful and easier to use than vue. The limitations of vue are too great,

answer the question point of the landlord:
1. State management, redux's state management is actually more reasonable and elegant than vue's state management, as to why I say this, because vuex's mutations actually has serious incompatibility with the state update of the extension operator or bug on the api design. This creates a lot of unnecessary code, and vuex's type is really disgusting.

2. In fact, the use of dispatch is not much different from that of vue, but for the specific difference, you should check the corresponding api and try it yourself.

3. Learning advice: now the most widely used domestic react is Alipay, it is strongly recommended to learn Alipay's antd front-end ui library, and ant-design-pro, a very good framework.


I remember that when I first started to learn react, I felt very familiar. I could write a todolist after reading it in an afternoon, because I had learned some vue, before, although I only did some simple demo, but many concepts of react have been found in vue, so I don't think a person who knows vue will not be able to learn react.
personally, you really can't put the cart before the horse when learning programming. Don't rush to see things like react-router and redux before theory comes first, just like vue can learn vue-router and vuex, directly before learning well.
it is recommended to start with Ruan Yifeng's react tutorial to understand these basic concepts.


you can go to react's official website, react's api, which has few and no instructions. Pure js data control view logic is not placed in the view.
as for the plug-ins, the learning cost of redux router is very low


it is recommended to follow the official tutorials . To be honest, the tutorials summarized in China sometimes lead to family buckets but do not explain clearly what each person is doing is a bit of a headache.

for example, redux is not actually exclusive to react , it is a JavaScript state container that provides predictable state management , but only supports react .

router , thunk are all introduced when you encounter some scenario problems, and you don't have to learn them all at the beginning.

one sentence: npm install-g create-react-app


do not use redux for beginners.

< hr >

someone once said such a sentence.

"if you don't know if you need Redux, you don't need it."

Dan Abramov, the creator of

Redux, added.

"you only need Redux when you have a problem that React really can't solve."


reference: https://github.com/allan2code.

Menu