Skip to content

Instantly share code, notes, and snippets.

View BrodaNoel's full-sized avatar
🏠
Working from home

Broda Noel BrodaNoel

🏠
Working from home
  • Remote
View GitHub Profile
import React from 'react';
import { View, TouchableOpacity } from 'react-native';
import duix from 'duix';
class Login extends React.Component {
onLoginClick = () => {
// here you do something to login the user
// ...
// then redirect to the Home page
import React from 'react';
import { View, TouchableOpacity } from 'react-native';
import duix from 'duix';
class Home extends React.Component {
onLogOutClick = () => {
// here you do something to logout the user
// ...
// then redirect to the Login page again
import React, { Component } from 'react';
import duix from 'duix';
// Pages
import Loading from './src/pages/Loading';
import Login from './src/pages/Login';
import Home from './src/pages/Home';
import Contact from './src/pages/Contact';
// ...more dependencies...
const DEFAULT_PAGE = 'Loading';
const unsubscribe = duix.subscribe('x', (x) => console.log(x));
unsubscribe();
duix.subscribe('user', (user) => {
console.log(user);
});
// or
duix.subscribe('user', (newUserValue, prevUserValue) => {
console.log('New User value is:', newUserValue);
console.log('Previous User value was:', prevUserValue);
});
const user = duix.get('user');
// or
const isLogged = duix.get('isUserLogged');
// or whatever
duix.set('user', { name: 'Noel' });
// or
duix.set('isUserLogged', true);
// or whatever
// src/components/Conditional.jsx
const Conditional = (props) => {
return(
!!props.if && props.children
);
}
export default Conditional;
// Implementation:
// src/components/Conditional.jsx
const Conditional = (props) => {
return(
!!props.if && props.children
);
}
export default Conditional;
// Implementation:
// Option 1
render() {
return (
<div className="App">
<h1>The title</h1>
{
this.state.movies.length > 0 && (
<h1>Movie list</h1>
<MovieList data={this.state.movies} />
)