S
S
Smuzzzzi2018-11-05 12:20:13
React
Smuzzzzi, 2018-11-05 12:20:13

What is the correct way to use this.props.children?

It is necessary that when switching to

<Route path="/user/:username/settings" component={UserProfileContainer.Settings} />

This.props.children changed
import UserProfileContainer from './containers/UserProfile';

My index
<Route path="/user/:username" component={UserProfileContainer} />

UserProfileContainer
return (
      <UserProfileDetail
        name={name}
      />
    );

UserProfileDetail
<main className="content">
  <div className="title">
     <h1>{name}</h1>
    <div>1 ссылка</div>
     <div>2 ссылка</div>
     <div>3 ссылка</div>
  </div>
  <div className="content">
     <h1>{this.props.children}</h1>
  </div>
</main>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-11-05
@Smuzzzzi

What is the correct way to use this.props.children?

import React from 'react';
import ReactDOM from 'react-dom';

const SomeComponent = ({ name }) => (
  <span>{name}</span>
);

const SomeContainer = ({ children }) => (
  <div>{children}</div>
);

const Example = () => (
  <SomeContainer>
    <SomeComponent name="John" />
  </SomeContainer>
);

ReactDOM.render(
  <Example />,
  document.getElementById('root');
);

Result:
<div id="root">
  <div>
    <span>John</span>
  </div>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question