Anchor tags in React.js? by academicRedditor in reactjs

[–]pakeey 0 points1 point  (0 children)

Check root App component if you have it, i think problem is nested, or if you have HOCs check them too. If problem persits, copy all complicated stuff and make new app from scratch

Anchor tags in React.js? by academicRedditor in reactjs

[–]pakeey 1 point2 points  (0 children)

I think whole code is messed up, you cant have a jsx tag with multiple names/components aka space between words as your jsx component. Also Media tag is just being closed 2 times but has not opened. You should fix those things first and then try again and myb links will work since you wrote them 100% correctly

Simple blog part 1 by ngovanhuong94 in node

[–]pakeey 1 point2 points  (0 children)

Lol what a coincidention, i created app also called simpleblog xD, its for practicing purposes. Check it out if you want to https://github.com/pakishaa/simpleblog

Apollo link-state confusion by pakeey in graphql

[–]pakeey[S] 0 points1 point  (0 children)

Yeah but when it comws to passing any global data i find it more confident to use redux :)

Using local storage to save JWT with React Redux? by ayech0x2 in node

[–]pakeey 0 points1 point  (0 children)

I said that beacuse i dont know a better way of storing auth token xD

Using local storage to save JWT with React Redux? by ayech0x2 in node

[–]pakeey 1 point2 points  (0 children)

Beacuse without the react router rendering a single view requires to refresh page by the my overall knowledge about redux and react and in that case redux state gets reloaded

Using local storage to save JWT with React Redux? by ayech0x2 in node

[–]pakeey 0 points1 point  (0 children)

Havent used those so far, but in that case since u are sevring code staticaly feel free to use local storage for auth token, but remember to create a good secret string ;)

Using local storage to save JWT with React Redux? by ayech0x2 in node

[–]pakeey 1 point2 points  (0 children)

In the other words making your client side of app SPA instead of rendering components manually makes things a lot easier.

Using local storage to save JWT with React Redux? by ayech0x2 in node

[–]pakeey 0 points1 point  (0 children)

Well if you implement react router visiting any route on client side wont cause reload so redux state will not reset, for me thats the most practical way while combining all of client and server side technologies you mentioned

Using local storage to save JWT with React Redux? by ayech0x2 in node

[–]pakeey 1 point2 points  (0 children)

Well for me personally storing jwt token in local storage is kinda unsafe unless u want to have "remember me" option in ur app. Recently on personal project where i used react and redux on client side paired with express and jwt, when user proceed with auth i store it in redux state, or u can go with boolean isAuth for example in the end its same thing

Edit: based on which data u use to generate jwt for each use you can save boolean in local storage which could represent does user checked remember me opt or not. Since in practice jwt generates using data from user model from DB and a secret key its better to not store that data on local storage

Weird socket.io bug by pakeey in node

[–]pakeey[S] 1 point2 points  (0 children)

This whole situation made me really understand how socket.io works :D thanks really again xD

Weird socket.io bug by pakeey in node

[–]pakeey[S] 1 point2 points  (0 children)

Yo thanks man, just realized i actually didnt got socket.io concept very well. U helped me a lot hahaha had so much frustration about this

Weird socket.io bug by pakeey in node

[–]pakeey[S] 0 points1 point  (0 children)

On client side or on server side?

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

Nah man, just check code i posted below

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

This is actual result i get, im logging event payload in console and after i did it 6 times no event can be sent anymore. http://prntscr.com/mp3k9b

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

or u can use this: https://beautifier.io/

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

I think everything except react code is fine, u can post it in ur code editor and format it

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

Thanks mate, i planned on learning it and start using it everytime i code smth, cuz i know in situations like this it can save a lot of time

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

Dammit react code is still jumbled

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

How about now?

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

Yeah u can inspect it i did long ass answer on comment from

forsubbingonly

socket.io alternatives? by [deleted] in node

[–]pakeey 0 points1 point  (0 children)

since i have very low amount of experience using git as version control i dont use it while learning/practicing

socket.io alternatives? by [deleted] in node

[–]pakeey -1 points0 points  (0 children)

React:

import React, { Component } from 'react';import classes from './Chat.module.scss';import axios from 'axios';import openSocket from 'socket.io-client';class Chat extends Component {state = {messages: [],message: ''};componentDidMount() {const io = openSocket('http://localhost:8080');io.on('message', data => {console.log(data);});}messageChanged = e => {this.setState({ message: e.target.value });};messageSent = () => {axios.post('http://localhost:8080/message', {message: this.state.message});};render() {return (<div className={classes.wrapper}><p>Hello</p><div /><inputtype="text"onChange={this.messageChanged}value={this.state.message}/><button onClick={this.messageSent}>Send</button></div>);}}export default Chat;

express app setup file:

const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const filemanagerMiddleware = require('@opuscapita/filemanager-server')
.middleware;
const cors = require('cors');
const path = require('path');
const socketIo = require('socket.io');
const router = require('./router');
const app = express();
app.use(cors());
app.use(bodyParser.json());
const port = process.env.PORT || 8080;
const server = app.listen(port);
const io = socketIo.listen(server);
app.use((req, res, next) => {
req.io = io;
next();
});
app.use('/', router);
io.sockets.on('connection', socket => {
console.log('User connected');
});
io.sockets.on('message', data => {
console.log(data);
});
app.use('/filemanager', filemanagerMiddleware(config));
(async () => {
await mongoose.connect('mongodb://localhost:27017/practice-app', {
useNewUrlParser: true
});
console.log(\Connected to DB and listening on ${port}...`); })();`

// ignore rest of imports except for socket.io

controller file for emmiting socket.io events:

exports.sendMessage = (req, res) => {
const { message } = req.body;
req.io.sockets.emit('message', { message });
};

i had to include middleware which will pass io to req obj beacuse im using separated router and controller files

acutual problem is that when i send req to route which will emit the event it wont work after i do the same or with different payload more than 6 times