Skip to content

Commit 6a05fce

Browse files
committed
fix: raise props priority over internal state
1 parent cde5af2 commit 6a05fce

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/UI.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717
*/
1818
class UI
1919
{
20-
21-
2220
/**
2321
* Initialize Leaf UI on a page
2422
* @return string
2523
*/
2624
public static function init(): string
2725
{
28-
return (
29-
implode(Core::$scripts) .
26+
return (implode(Core::$scripts) .
3027
static::createElement('script', [
3128
'src' => '/vendor/leafs/ui/client/dist/ui.cjs.production.min.js',
3229
], [''])
@@ -103,7 +100,11 @@ public static function component(string $component, array $props = []): string
103100
$component = new $component;
104101

105102
if (!$component->key) {
106-
$component->key = $props['key'] ?? Utils::randomId($component::class);
103+
$component->key = Utils::randomId($component::class);
104+
}
105+
106+
if ($props['key'] ?? false) {
107+
$component->key = $props['key'];
107108
}
108109

109110
Core::$state[$component->key] = array_merge(get_class_vars($component::class), Core::$state[$component->key] ?? [], ['key' => $component->key], $props);

0 commit comments

Comments
 (0)