How to use the preact.cloneElement function in preact

To help you get started, we’ve selected a few preact examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github developit / preact-transition-group / src / TransitionGroup.js View on Github external
render({ childFactory, transitionLeave, transitionName, transitionAppear, transitionEnter, transitionLeaveTimeout, transitionEnterTimeout, transitionAppearTimeout, component, ...props }, { children }) {
		// TODO: we could get rid of the need for the wrapper node
		// by cloning a single child
		let childrenToRender = [];
		for (let key in children) if (children.hasOwnProperty(key)) {
			let child = children[key];
			if (child) {
				let ref = linkRef(this, key),
					el = cloneElement(childFactory(child), { ref, key });
				childrenToRender.push(el);
			}
		}

		return h(component, props, childrenToRender);
	}
}
github ajainvivek / preact-fluid / src / Form / RadioGroup / RadioGroup.js View on Github external
renderRadio = (child, index) => {
		const selectedValue = this.selectedValue;

		return cloneElement(child, {
			checked: selectedValue ? child.props.value === selectedValue : index === 0,
			key: index,
			onChange: this.handleOnChange,
			disabled: this.props.disabled,
			...child.props
		});
	}
github xialvjun / preact-flyd / src / reactive.js View on Github external
render() {
      const {children$: children, ...props} = {...this.props, ...this.state};
      if (tag) {
        return h(tag, props, ...children);
      }
      return children instanceof VNode ? cloneElement(children, props) : children;
    }
  }
github RocketChat / Rocket.Chat.Livechat / src / components / ButtonGroup / index.js View on Github external
		{children.map((child) => cloneElement(child, { className: createClassName(styles, 'button-group__item') }))}
github lucafalasco / preact-custom-scrollbars / src / Scrollbars / index.js View on Github external
return h(tagName, { ...props, style: containerStyle, ref: (r) => { this.refs.container = r } }, [
      cloneElement(
                renderView({ style: viewStyle }),
                { key: 'view', ref: (r) => { this.refs.view = r } },
                children
            ),
      cloneElement(
                renderTrackHorizontal({ style: trackHorizontalStyle }),
                { key: 'trackHorizontal', ref: (r) => { this.refs.trackHorizontal = r } },
                cloneElement(renderThumbHorizontal({ style: thumbHorizontalStyleDefault }), { ref: (r) => { this.refs.thumbHorizontal = r } })
            ),
      cloneElement(
                renderTrackVertical({ style: trackVerticalStyle }),
                { key: 'trackVertical', ref: (r) => { this.refs.trackVertical = r } },
                cloneElement(renderThumbVertical({ style: thumbVerticalStyleDefault }), { ref: (r) => { this.refs.thumbVertical = r } })
            )
    ])
  }
}
github RocketChat / Rocket.Chat.Livechat / src / components / Form / FormField / index.js View on Github external
						.map((child) => cloneElement(child, { error: !!error }))
					: children}
github developit / preact-css-transition-group / src / CSSTransitionGroup.js View on Github external
newChildren = newChildren.map( c => {
				if (!c.props[showProp] && isShownInChildren(prevChildMapping, c, showProp)) {
					c = cloneElement(c, { [showProp]:true });
				}
				return c;
			});
		}
github davidbailey00 / ninetales / packages / head / src / browser / index.js View on Github external
function stripDataJsx(child) {
  return cloneElement(child, { "data-jsx": undefined });
}
github synacor / preact-i18n / src / components / localizer.js View on Github external
export function Localizer({ children }, { intl }) {
	let child = children && children[0];
	return child && cloneElement(child, translateMapping(child.attributes, intl, true));
}
github matthewmueller / preact-head / index.js View on Github external
.map((c) => {
    const className = (c.className ? c.className + ' ' : '') + 'preact-head'
    return cloneElement(c, { className })
  })
}