react link vs a tag and arrow function

后端 未结 4 1893
陌清茗
陌清茗 2020-12-05 13:52

Hi guys I\'m a beginner programmer just started on react router.

I have two questions. What is the difference between using an

4条回答
  •  一向
    一向 (楼主)
    2020-12-05 14:12

    The component allows you to do more than the normal link element. For instance, because it's a React component you have the benefits of having a state and what not (if you want that). You can see more documentation on here. Without the error I'm not sure what happens, but I suspect the routing library wants you to use the component, over a normal html element.

    With regards to () => {} this is a construct which is called an anonymous function, or a lambda expression. It's basically the same as saving a function in a variable: var x = function(){ return (

    ...) }; if you have anything in the first parenthesis, it's a parameter which you have access to: const x = (y) => return y*2; The reason it's done in React is to expose the function scope to the component it lies in.

提交回复
热议问题