Skip to content

Commit 3a7f4b3

Browse files
committed
update README with new hook usage
1 parent 5075f97 commit 3a7f4b3

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@ IDOM can be used to create a simple slideshow which changes whenever a user clic
4545
import idom
4646

4747
@idom.element
48-
async def Slideshow(self, index=0):
49-
50-
async def next_image(event):
51-
self.update(index + 1)
52-
48+
async def Slideshow():
49+
index, set_index = idom.hooks.use_state(0)
5350
url = f"https://picsum.photos/800/300?image={index}"
54-
return idom.html.img({"src": url, "onClick": next_image})
51+
return idom.html.img({"src": url, "onClick": lambda event: set_index(index + 1)})
5552

5653
server = idom.server.sanic.PerClientState(Slideshow)
5754
server.daemon("localhost", 8765).join()

0 commit comments

Comments
 (0)