Supported cryptocurrencies:
BTC BTC
BCH Bitcoin Cash
NANO NANO
0.0001 BCH
EnglishNeed help to better understand the protected route on React

Hello all, can anyone explain me these 3 lines on the code? line 5: component: Component, ... rest line 8 {...rest} line 9 props line 11 as I understand is the user properties. Protected Route are used as a way for an authorized user to get access to a component. For example Members area.

godzilla34 1 month ago
    Tags:
  • Code
  • React
  • Programming
question_image


kimo2 1 month ago
https://www.techiediaries.com/react-spread-operator-props-setstate/
https://stackoverflow.com/questions/43484302/what-does-it-mean-rest-in-react-jsx
kimo2 1 month ago Correct
Well, let's say you have a such route:
<ProtectedRoute path="/private" component={PrivateArea} />

So, when the above component is called, this happens:

line 5:
var Component = PrivateArea
var rest = *remaining properties*
you can add console.log(Component); console.log(rest); between line 5 and 6 to check it

line 8:
'rest' is passed to Route, so ProtectedRoute works as a wrapper for Route component.

line 9: standard rendering routine for Route component
props is an object, which contains Route component attributes, including those, which were passed through 'rest' var.
Add 'console.log(props);' before if-statement.

line 11:
call PrivateArea component (because Component=PrivateArea)
godzilla34 1 month ago
Great explanation. Thank you.
Ahmad 1 month ago
Refugees in tents are in dire need of aid
test 1 month ago
test
Ahmad 1 month ago
Refugees in tents are in dire need of aid