V
V
vaskadogana2017-04-25 15:07:21
React
vaskadogana, 2017-04-25 15:07:21

How to write a component that will return the component that was put in it?

below is an example. The bottom line is that I want the MayBeHidden component to subscribe to the store and, depending on the user's rights, return the content or not. But faced that:
1. a component which returns and accepts a lodge, values. In the case of a variable, I wrote {...this.props}, but here I slow down something
2. what I plan to put inside a rather different plan, from a button / form to a table or an entire page.

<MayBeHidden>
            <BtnAdd 
                pasword_placeholder = {'Введите пароль'} 
                name_placeholder = {'Введите имя'} 
                btnname = {'Добавить пользователя'}
                dataFromform = {this.adduser}
                kindUser = {'User'}
                defaultgroup = {this.props.login}
            >    
            </BtnAdd>  
</MayBeHidden>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Prozorov, 2017-04-29
@vaskadogana

render() {
  const isHidden = false; 

  if (isHidden) return null;

  return <children.type {...children.props} additionalProp="an value" />;
}

E
Evgeniy Kvasyuk, 2017-04-25
@EvgeniyKvasyuk

https://habrahabr.ru/post/309422/ - a wonderful article, after which you can easily write a High order component

M
Mikhail Osher, 2017-04-25
@miraage

render() {
  return <div>{this.props.children}</div>
}

D
davidnum95, 2017-04-25
@davidnum95

For such cases, it is more correct to use HOC.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question