Posts

Showing posts with the label reactjs

Downloading excel data using Axios from Laravel backend is not working

Image
Clash Royale CLAN TAG #URR8PPP Downloading excel data using Axios from Laravel backend is not working I am developing a Web application using React JS for the front-end and Laravel for the back-end API. Now, what I am trying to do is I am trying to fetch the excel data from the backend using axios and then download the file. This is my laravel API controller action method. function downloadExcel(Request $request) { //other code goes here return Excel::create($left_photo->id . "-" . $right_photo->id, function($excel) use ($excel_data) { // Set the spreadsheet title, creator, and description $excel->setTitle('Mapping points'); $excel->setCreator('Laravel')->setCompany('Memento'); $excel->setDescription('Mapping points file'); // Build the spreadsheet, passing in the payments array $excel->sheet('sheet1', function($sheet) use ($exce...

How to correctly map a set of data onto a table using React

Image
Clash Royale CLAN TAG #URR8PPP How to correctly map a set of data onto a table using React I am trying to map data to the correct columns using react and am struggling to get everything to display in the correct column. Here is my data structure which consists of an array of data - in this original array each object has a norm_data and and feature_data key - which again consists of an array of data with the same keys. [ { "norm_data": [ { "avg": 0, "panelist": 0, "feature": "Headline", "exists": false }, { "avg": 0, "panelist": 0, "feature": "Small Print", "exists": false }, { "avg": 0, "panelist": 0, "feature": "Call to Action", "exists": false }, { "avg": 0, ...

TypeError: Cannot read property 'map' of undefined ReactJS API calls

Image
Clash Royale CLAN TAG #URR8PPP TypeError: Cannot read property 'map' of undefined ReactJS API calls I have recently been trying to play with APIs in React.js, I believed the below code would have worked, based on a tutorial from https://reactjs.org/docs/faq-ajax.html, However when I run this code I keep getting TypeError: Cannot read property 'map' of undefined Below is my code, this is a component called DOTA and is exported to my App.js import React from 'react'; const API_KEY ="some-api-key"; const DEFAULT_QUERY = 'redux'; class DOTA extends React.Component { constructor(props) { super(props); this.state = { error: null, isLoaded: false, info: , }; } componentDidMount() { fetch(API_KEY + DEFAULT_QUERY) .then(response => response.json(console.log(response))) .then((result) => { console.log(result) this.setState({ isLoaded: true, info: result.i...

React native Release Apk Building Error

Image
Clash Royale CLAN TAG #URR8PPP React native Release Apk Building Error I'll build my react native project it build success, but whenever i will try to build release Apk It's give error error: uncompiled PNG file passed as argument. Must be compiled first into .flat file.. 2 Answers 2 Try this... in your gradle.properties file add these lines android.enableAapt2=false That's not working for me – Akshay Italiya 2 hours ago This is the known issue of react-navigation library. As a workaround you need to add this line to gradle.properties file: react-navigation gradle.properties android.enableAapt2=false and clean all previous build files using: ./gradlew clean By clicking "Post Your Answer"...

How to update component based on container's state change

Image
Clash Royale CLAN TAG #URR8PPP How to update component based on container's state change I have a React container called UserContainer which renders a component called UserComponent . UserContainer UserComponent The code looks approximately like this (I have removed the unnecessary bits): // **** CONTAINER **** // class UserContainer extends React.Component<ContainerProps, ContainerState> { state = { firstName: "placeholder" }; async componentDidMount() { const response = await this.props.callUserApi(); if (response.ok) { const content: ContainerState = await response.json(); this.setState({ firstName: content.firstName }); } } private isChanged(componentState: ComponentState) { return this.state.firstName === componentState.firstName; } async save(newValues: ComponentState) { if (!this.isChanged(newValues)) { console.log("No changes detected."); ...

Why redux is required for React Native mobile App?

Image
Clash Royale CLAN TAG #URR8PPP Why redux is required for React Native mobile App? I am experience developer of native android app but I am entry level developer for React Native. I am familiar with basic but not able to understand why Redux is used with React Native? I want understanding of Redux feature in respect to Android Native App using java 3 Answers 3 Redux is not "mandatory" in a React Native mobile application. It is just an optional state management library that usually been used in a medium/large React Native application. Think Redux as a state management over the application. For example, you log in as a user called "Tom". With Redux, you can save the user data into a "store". Then when you want to use it in a profile/account page, you just need to grab the user data from your "store" and display it. Now imagine if you don't have a Redux. When...

Enzyme - Mock non-instance variables

Image
Clash Royale CLAN TAG #URR8PPP Enzyme - Mock non-instance variables I have the following React Component: const titleText = translate('header.about'); const About = ({onClose}) => ( <div> <ModalHeader title={titleText} onClose={onClose} /> <Content /> </div> ); I also have a test file that checks the onClose functionality, which works fine: onClose const spy = sinon.spy(); const wrapper = shallow(<About onClose={spy} />); // I also tried "mount()" ... assert.equal(spy.callCount, 1, 'onClose was called exactly once'); However, I get the following warning in the terminal when running the test: Warning: Failed prop type: The prop `title` is marked as required in `ModalHeader`, but its value is `undefined` I don't get the warning in the browser, only when running the test. While it's only a warning, I'd rather fix this if possible. Any way to give a mock value to title ? I am only interested in possible so...

How to hide the form from unauthorized users

Image
Clash Royale CLAN TAG #URR8PPP How to hide the form from unauthorized users The form of adding information to the page works regardless of whether the user is authorized or not, how can I hide the form from unauthorized users? An unauthorized user can not use the form, but it is still visible to him. index.js import React, { Component } from 'react'; import HolidayItemsList from './holidays/holidays_list' import HolidaysForm from './holidays/holidays_form' export default class Holidays extends Component { render() { return ( <div> <h3>Holidays</h3> <HolidayItemsList /> <HolidaysForm /> </div> ); } } index_form.js ........ render() { return ( <div className='col-sm-4'> <Formsy.Form onSubmit={ this.handleSubmit.bind(this) }> <div className="form-group"> <label for="na...

Load more when scrolled to bottom in Reactjs

Image
Clash Royale CLAN TAG #URR8PPP Load more when scrolled to bottom in Reactjs This is my post-card page(only the specific part) where i am displaying data from fetched Api. fetchMoreData(){ this.setState({ index: this.state.index + 5 }) } componentDidMount(){ window.addEventListener('scroll', this.onScroll); this.fetchMoreData(); } onScroll = () => { $(window).scroll(function() { if($(window).scrollTop() + $(window).height() == $(document).height()) { this.fetchMoreData(); } }); } As My API is a testing API i fetch all the data in my posts page and then pass it to my post-card page so on change of this.state.index it displays more item. The issue I am facing is that I get an error that this.fetchMoreData() is not a function. Feel free to point out any mistakes. 2 Answers 2 Make fet...

React Native Material top navigator doesn't show the screens

Image
Clash Royale CLAN TAG #URR8PPP React Native Material top navigator doesn't show the screens I have the navigator that renders two lists, it works If I add scrollEnabled, otherwise it doesn't, also if I try to specify tab width it doesn't render the lists.. Here is the working code, but it shows the navigator like this: first list | second list | blank space import { createMaterialTopTabNavigator } from "react-navigation"; import ReadList from "../components/ReadList"; import ReadingList from "../components/ReadingList"; import { primaryColor } from "../styles/colors"; export default createMaterialTopTabNavigator( { Read: ReadList, Reading: ReadingList }, { tabBarOptions: { scrollEnabled: true, labelStyle: { fontSize: 12, color: primaryColor, fontFamily: "Raleway SemiBold" }, style: { ...

Reactjs :- How to solve this

Image
Clash Royale CLAN TAG #URR8PPP Reactjs :- How to solve this I created a web-app that uses reactjs. Now the basics of the app are :- Now 2nd task is explained as :- Now I want to share the topic with link , however on clicking any of the topic only one elemnt of the html renders and the url remains the same. So this is what i want to do - you can use axios, fetch, request library for api call – Shubham Agarwal Bhewanewala 1 min ago By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Why React ref return Ant? How to use it?

Image
Clash Royale CLAN TAG #URR8PPP Why React ref return Ant? How to use it? My code like this render() { return ( <div> <Layout ref={element => this.ipDetailDOM = element} id="ip-detail"> ... </layout> </div> ) } But this.ipDetailDOM return an Adapter Object. this.ipDetailDOM Adapter Adapter {props: {…}, context: {…}, refs: {…}, updater: {…}, _reactInternalFiber: FiberNode, …} I do not know to use it? How does the layout component look like, also , it it created using an HOC – Shubham Khatri 24 mins ago How did you create the ref ? using createRef() ? – Abinthaha 18 mins ago ref createRef() ...

How to style material-ui textfield

Image
Clash Royale CLAN TAG #URR8PPP How to style material-ui textfield I have been trying to work out how to style a material-ui.next textfield (https://material-ui-next.com/demos/text-fields/) component (React JS). <TextField id="email" label="Email" className={classes.textField} value={this.state.form_email} onChange={this.handle_change('form_email')} margin="normal" /> My classes are created as follows (I have attached relevant part): const styles = theme => ({ textField: { width: '90%', marginLeft: 'auto', marginRight: 'auto', color: 'white', paddingBottom: 0, marginTop: 0, fontWeight: 500 }, }); My problem is that I can not seem to get the colour of the text field to change to white. I seem to be able to apply styling to the overall text field (because the width styling works etc)... but I think the problem is that I am ...

ReactJS query variables

Image
Clash Royale CLAN TAG #URR8PPP ReactJS query variables Not sure what I am doing wrong but I receiving the following error message after I click on the submit button: The code for query is as follows: const ObjectQuery = gql` query($timestamp: Float!){ action(timestamp: $timestamp){ action timestamp object{ filename } } } `; class UserList extends React.Component { render() { return ( ({ loading, error, data }) => { if (loading) return <p>Loading...</p>; if (error) { console.log(error); return <p>Error</p>; } if (data.action.length === 0) return <div>No Objects</div>; return (//this code binds the query above to the output and puts it on the screen. <Item.Group divided> {data.action.map(action => ( <div> <ul> <li key = {actio...

How to pass data in nested components?

Image
Clash Royale CLAN TAG #URR8PPP How to pass data in nested components? I wonder how to pass data in nested components. I'm making an app using react-native with react-redux, redux-thunk, redux-persist. Based on what I understand about the conception of redux, even though it is consist of nested components, can get or update state from store. However, I'm doing that only pass data as props from parent component to children components. I guess it is not correct usage of redux because the more depth is deeper, the more I have to call functions of parent components. Sounds weird, right? If you see my code, then you would understand what I'm talking about. Here's my code. UPDATED For example, code structure is like bellow. If I want to call action in grandChild component, Should I go up to parent Component? parent.js ... getData = async () => { await Actions.func(); } render() { return ( <Parent> <Child data={data} getData={this.getData...

How to connect reactjs with express api?

Image
Clash Royale CLAN TAG #URR8PPP How to connect reactjs with express api? I had created a new react application and then installed express and body-parser and express-router, Now i want to connect a express Api to the application for event-driven application. How do i connect it ? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.