Skip to main content

props, state, and this. - stream-of-learning

As I look around the web for help understanding my troubles in React Native, I figure I'll just take notes as I go here, to document the process.

Right away, I learned something from this site (that I probably already saw someplace on the React Native documentation but it didn't stick):
"Components receive props from their parent. These props should not be modified inside the component."
This explains a lot. The line initializing player 1 looked like const player1 = new Player((name = "playa1"), (turn = true));. Setting the name with the props is fine, but setting "turn" with props doesn't make sense if props are immutable; turn needs to toggle from true to false repeatedly during normal Tic Tac Toe gameplay. This doesn't give me a solution but helps explain some of the problem.

I'm starting to wonder if turn should even be an attribute of the player at all. It might be easier to just have a global variable like "isPlayerOnesTurn" or something that just toggles. I think when I started, this was my plan, but somehow ended up going the player.turn route instead.

Still on I'm starting to feel like if I can understand what this sketch is doing, I'll be pretty close to my answer:

I can see that these .defaultProps() and .propTypes()

Another helpful bit here - I already knew "state" was mutable (that's what setState is for), but this site further clarifies that
State is internal to a component, while props are passed to a component.
This is good stuff. Still not answering my question about super(), but another great sketch here that I think I can use as a template for what I'm trying to do:

I'm calling it a night on Tic Tac Node for tonight, but feeling ready to get this thing working later this week!


Popular posts from this blog

Setting up an RStudio Server

I'm taking a break from React Native (our group decided not to use it for the Tic Tac Toe project) and wanted to put some thoughts in here about setting up my RStudio server for my SOTU-db project.

I won't get into the details of why I want the RStudio server here - that will be covered on the SOTU-db dev blog. Here, I just want to record some quick thoughts and problems that arose as I set up the server.  Gaining access to the server The server itself is a VM provided by Loyola University Chicago's Computer Science Department - thanks to George Thiruvathukal and Miao Ye for setting me up with this and providing support. 
I initially ran into issues because I couldn't figure out how to connect to the server. I knew I had been assigned a static IP and a DNS entry in Loyola's nameservers at, and assumed I would use SSH to connect to the server (which I further assumed was running Ubuntu in accordance with CS departmental policy and my previous expe…

New Position with Chicago Metro History Fair

I'm excited to have begun a new position at the Chicago History Museum a couple of weeks ago now. I am a "History Fair Program Specialist," meaning I help run the Chicago Metro History Fair.

The Chicago Metro History Fair (CMHF) is an annual, regional competition where middle and high school students in and around Chicago research a historical topic of their choice and create projects (exhibit boards, websites, documentaries...) that show off their hard work. Volunteer judges from around the community help provide feedback on the students' work, and winning entries can advance to state and national level competitions (administered by Illinois History Day and National History Day, respectively).

So far, my work has primarily been in preparing for weekend "Palooza" events, where volunteer coaches (often history teachers, faculty, graduate students, etc) and librarians assist students with their History Fair projects. The regional competition will take place i…

More tic tac node

Well I am feeling pretty good about my progress with React Native, but haven't done any more coding in the last couple of days. I just re-opened the project again today and thought I'd blog about some of my as-yet unsolved challenges!

I like loops Things with declaring and initializing variables are really different than what I'm used to. In Processing and Python, global variables can be declared and re-declared wherever, and the draw loop will "pick up" those changes and return the desired results. For example, in Processing, I could initialize the integer "y" to 5 with int y = 5; then inside the draw loop, call println(y); to repeatedly print "5" to the console. If I then call a function that just does y=7; the console will start printing "7" repeatedly, since it recognizes the new value of y.

I used this a lot to build setter functions, for example initializing all the entries in the squareStates array in Tic-Tac-Tohmygod (my Proc…