Comments (2)
I tested this on my end and it worked:
![Screenshot 2023-08-29 at 9 27 39 PM](https://private-user-images.githubusercontent.com/84860195/264132390-8ffd5bb1-37f5-4ed1-b7e2-d3abbec3ee13.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTA0NTIwODUsIm5iZiI6MTcxMDQ1MTc4NSwicGF0aCI6Ii84NDg2MDE5NS8yNjQxMzIzOTAtOGZmZDViYjEtMzdmNS00ZWQxLWI3ZTItZDNhYmJlYzNlZTEzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDAzMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwMzE0VDIxMjk0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU3ZWFhNTdiMTE4ZmE5MmQ0ZGY3YmU3NWU1ZGU2NmE0ZjFiNjM2MzBhYjBjY2JiOTUxZWNlODQwMjlhMzMwMTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.fMo6bCDd5WuTbWHzT5JeaT7oJtPw-BHXMV-a2U3ckeA)
This is what I did:
- In the file where you want to put the counter:
from app.core.base import RxBasePage
from app.helpers.nav_helpers import NavHelper
import reflex as rx
from app.states.counterState import CounterState
def CounterComponent():
return rx.box(
rx.text("Counter App", font_size="1.5em"),
rx.spacer(),
rx.hstack(
rx.button(
rx.icon(tag="add"), color="green", on_click=CounterState.increment
),
rx.text(f"{CounterState.count}"),
rx.button(
rx.icon(tag="minus"), color="red", on_click=CounterState.decrement
),
),
)
class RxPage:
# Title of page: must match high-level key in config.py
def __title__(self):
return "Reflexfy"
# Page route path: must follow /parent-key/file-name *without .py extension*
def __route__(self):
return "/"
# Left navigation panel: automated based on config navigation order
def __left_navigation__(self):
nav: list = NavHelper.__get_left_navigation__(self.__title__())
return NavHelper.__set_left_navigation__(nav)
# Right navigation panel: TBD
def __right__navigation__(self):
return []
# Mobile navigation drop down
def __mobile_navigation__(self):
return NavHelper.__get_left_navigation__(self.__title__())
# Main content area: takes in rx.Componenets and passes them to base file
def __components__(self):
return [CounterComponent()]
# Build method: creates a new instance for the page above
def build(self):
page = RxBasePage(
self.__components__(),
self.__left_navigation__(),
self.__right__navigation__(),
self.__mobile_navigation__(),
)
return page.build()
- Place your states all in the
states
folder - it'll be easier to organize and keep track of. Inside ofstates
i created a file calledcounterState.py
and placed the following code as such:
from .mainState import MainState
class CounterState(MainState):
count: int = 0
def increment(self):
self.count += 1
def decrement(self):
self.count -= 1
This i what I did and the counter worked.
Don't place your own components, like the counter, outside the app
folder. This messes with the path, even if you're using Reflex plainly, always place the files inside the main directory. So for example, your content
folder, place it inside the app
folder and this way you'll have access to it easily.
from reflexify.
Thanks it worked.
from reflexify.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reflexify.