| 153 | } |
| 154 | |
| 155 | render() { |
| 156 | const { children, render } = this.props; |
| 157 | const { matches } = this.state; |
| 158 | |
| 159 | const isAnyMatches = |
| 160 | typeof matches === "object" |
| 161 | ? Object.keys(matches).some(key => matches[key]) |
| 162 | : matches; |
| 163 | |
| 164 | return render |
| 165 | ? isAnyMatches |
| 166 | ? render(matches) |
| 167 | : null |
| 168 | : children |
| 169 | ? typeof children === "function" |
| 170 | ? children(matches) |
| 171 | : !Array.isArray(children) || children.length // Preact defaults to empty children array |
| 172 | ? isAnyMatches |
| 173 | ? // We have to check whether child is a composite component or not to decide should we |
| 174 | // provide `matches` as a prop or not |
| 175 | React.Children.only(children) && |
| 176 | typeof React.Children.only(children).type === "string" |
| 177 | ? React.Children.only(children) |
| 178 | : React.cloneElement(React.Children.only(children), { matches }) |
| 179 | : null |
| 180 | : null |
| 181 | : null; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /** |