Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

passing multiple props to child component in react

<ChildComponentName value1={this.state.value1} value2={this.state.value2}/>
Comment

multiple child.props in reactjs

import { Children } from 'react'

const Sample = ({ title, children }) => {
  let _body, _title

  Children.forEach(children, child => {
    if (child.type === SampleTitle) {
      return _title = child
    }

    if (child.type === SampleBody) {
      return _body = child
    }
  })

  if (!_title) _title = <div className='title'>{title}</div>
  if (!_body) _body = <div className='title'>{children}</div>

  return (
    <div className='panel'>
      {_title}
      {_body}
    </div>
  )
}

const SampleTitle = ({ children }) => <div className='title'>{children}</div>
const SampleBody = ({ children }) => <div className='body'>{children}</div>

Sampe.Title = SampleTitle
Sample.Body = SampleBody


// Now you can apply

<Sample title="my title">
  <div>my body</div>
</Sample>

<Sample title="my title">
  <Sample.Body>my body</Sample.Body>
</Sample>

<Sample title="my fallback title">
  <Sample.Title>my overriding title</Sample.Title>
  <Sample.Body>my body</Sample.Body>
</Sample>
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord.js messageUpdate 
Javascript :: copia independiente array javascript 
Javascript :: concat emoji with text in react js 
Javascript :: how to add toggle class in javascript using css modules 
Javascript :: js objects 
Javascript :: find intersection between two object arrays javascript 
Javascript :: scroll up own 
Javascript :: discord.js buttons 
Javascript :: add object in array state react 
Javascript :: how to map through an object javascript 
Javascript :: add column sequelize 
Javascript :: for in loop javascript 
Javascript :: add two floating point numbers jquery 
Javascript :: how to add an event listener to a function javascript 
Javascript :: react native update state array of objects 
Javascript :: methods javascript 
Javascript :: check if a string matches a regex javascript 
Javascript :: access to nested properties on javascript using property names 
Javascript :: make a function and return the index of specific character in javascript 
Javascript :: angularjs show form validation errors 
Javascript :: find multiples of a number 
Javascript :: get element of selection javascript 
Javascript :: accesing jest from bin 
Javascript :: jquery xpath 
Javascript :: can we fine a key with help of value in array of objects javascript 
Javascript :: absolute price in javascript 
Javascript :: exceljs font family 
Javascript :: recaptcha v3 
Javascript :: mongooseautoincrement 
Javascript :: redireccionar a una página con javascript después de un tiempo 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =