Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update refs.mdx #1127

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/routes/concepts/refs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function App() {
<button onClick={() => setShow((isShown) => !isShown)}>Toggle</button>

<Show when={show()}>
<p ref={setElement}>This is the ref element</p>
<p ref={element}>This is the ref element</p>
</Show>
</div>
)
Comment on lines 86 to 92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great pickup! looking at the two, there are multiple things that need to be updated within this code snippet from the playground. Do you mind updating it to reflect that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only thing I would add to the code snippet from the playground ist the code from createEffect. The other things looks fine. If you agree, I can update the PR.

Maybe it would be a good thing to change parameter in the setShow function vom (v) => !v to (isShown) => !isShown. What are your thoughts on that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the createEffect itself is necessary. I mostly mean that the code snippet should look like this:

function App() {
  const [show, setShow] = createSignal(false);
  let element!: HTMLParagraphElement;

  return (
    <div>
      <button onClick={() => setShow((isShown) => !isShown)}>Toggle</button>

      <Show when={show()}>
        <p ref={element}>This is the ref element</p>
      </Show>
    </div>
  );
}

Since we don't need the setElement in this, we can do without the signal itself!

Expand Down
Loading