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

Bug in @use_state or incorrect usage? #16

Closed
sprig opened this issue Jul 29, 2024 · 2 comments
Closed

Bug in @use_state or incorrect usage? #16

sprig opened this issue Jul 29, 2024 · 2 comments

Comments

@sprig
Copy link

sprig commented Jul 29, 2024

Hi!

I'm exploring this package through the documentation at https://juliapluto.github.io/PlutoHooks.jl/src/notebook.html
When attempting to use @use_state it seems that cells that reference state or set_state are being constantly rerun/updated (see the cell runtime ticker going crazy in the video below). Am I using it correctly or are state/set_state supposed to be referenced only in the cell where they got created?

https://github.com/user-attachments/assets/36bdc32d-917b-413b-a11a-421a4db343d5
Using

Pluto v0.19.43
PlutoHooks v0.0.5
@sprig
Copy link
Author

sprig commented Jul 29, 2024

Forgot to write the actual code (although it's shown in the video):

### A Pluto.jl notebook ###
# v0.19.43

using Markdown
using InteractiveUtils

# ╔═╡ 5837b136-4dc4-11ef-37b2-45376988aac0
using PlutoHooks

# ╔═╡ d30d0a1d-bd53-4ed0-bd3a-d0da8a6fbc05
state, set_state = @use_state(0)

# ╔═╡ 7253fa89-b031-479c-9b1c-f90c5827ef8b
set_state(42)

# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
PlutoHooks = "0ff47ea0-7a50-410d-8455-4348d5de0774"

[compat]
PlutoHooks = "~0.0.5"
"""

# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.4"
manifest_format = "2.0"
project_hash = "b183d4a92ada66904f13ca4ec2a47f0a6d5358d7"

[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[deps.InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[deps.Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.PlutoHooks]]
deps = ["InteractiveUtils", "Markdown", "UUIDs"]
git-tree-sha1 = "072cdf20c9b0507fdd977d7d246d90030609674b"
uuid = "0ff47ea0-7a50-410d-8455-4348d5de0774"
version = "0.0.5"

[[deps.Random]]
deps = ["SHA"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
"""

# ╔═╡ Cell order:
# ╠═5837b136-4dc4-11ef-37b2-45376988aac0
# ╠═d30d0a1d-bd53-4ed0-bd3a-d0da8a6fbc05
# ╠═7253fa89-b031-479c-9b1c-f90c5827ef8b
# ╟─00000000-0000-0000-0000-000000000001
# ╟─00000000-0000-0000-0000-000000000002

@sprig
Copy link
Author

sprig commented Jul 29, 2024

Well, using set_state from inside a @use_effect cells appears to work correctly, i.e. without triggering a constant update. I'm guessing that's the intended usage so will close this.

@sprig sprig closed this as completed Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant